HttpContext.Current.Session is null

Welcome to Wisej Support.
Questions, suggestions and plain old bugs - are all welcome here!


I uses a third party application framework, in which HttpContext.Current.Session is used to store system data like authentication, system variables ….

However in Wisej,  HttpContext.Current.Session is always null. Please advise how to resolve this issue?

Thank You.


  • You must to post comments

Hello Tung,

The issue is that the asynchronous handler in Wisej doesn’t require the AspNet session – it can handle simultaneous requests really really fast.

You can add this class to your app to require the AspNet session to be created:

namespace Wisej.Core
  public class HttpHandlerRequiresSession : Wisej.Core.HttpHandler, System.Web.SessionState.IRequiresSessionState
    // no code required.

Then modify your Web.config file like this:

  <add name="wisej" verb="*" path="*.wx" type="Wisej.Core.HttpHandlerRequiresSession, [Assembly Name]"/>

Now all Wisej HTTP requests can use HttpContext.Current.Session.

Notice that I bolded HTTP. That’s because the traditional AspNet session cannot possibly work with WebSocket requests. But you can solve this in two alternative ways:

  1. Disable WebSocket: add “enableWebSocket”: false to your Default.json. See
  2.  Keep WebSocket enabled and in your Program.Main() add this:
           Application.Session.AspNetSession = HttpContext.Current.Session;

It saves the AspNet session with the Wisej session, which works with WebSocket.

Solution 1 works with the AspNet code that  you mentioned. Solution 2 won’t work since HttpContext.Current.Session for those library will always be null on a WebSocket call.




  • Luca (ITG)
    I forgot to add that you should be careful with AspNet sessions since they lock – a second request will block and wait until a previous request is done using the session. You can solve that using the IReadOnlySessionState instead of IRquiresSessionState. But a read-only session is read-only… That’s ASP.NET/MVC.
  • Tung Ngo
    Hello Luca, Thanks for your instruction on how to enable HttpContext.Current.Session. Is there any performance penalty of disabling Websocket ? BR,
  • Luca (ITG)
    There is a small performance penalty and you lose the ability to push updates to the client from background tasks or long running requests. If you need to push updates to the client, you can add a timer component to the page (window, form) that needs to be updated (update a progress bar, for example), set the timer to fire every few seconds and Wisej will be able to “push” the updates using http. Additionally, http has few hundred bytes of overhead for each request, while WebSocket doesn’t. In any case, running Wisej just with http is still a lot faster than ASP.NET/MVC.
  • Tung Ngo
    I’m exciting about capability of push data from server to Client. I have read that Signal R can do this. But not expect that Wisej supports this feature as well.
  • Luca (ITG)
    Wisej is built for WebSocket see We don’t use SignalR – it’s a relative large library mostly built when WebSocket was a new technology not available consistently and it provided a uniform interface, plus long polling for when WebSocket is not available. Wisej uses the WebSocket feature directly, it also compresses large packets, and falls back to plain HTTP without long polling.
  • You must to post comments

Hello Tung,

I think you can use Application.Session to dinamically define session variables:

string Name;
int Id;

Name = “Jack”;
Id = 125;

Application.Session.UserId = Id;
Application.Session.UserName = Name;

then use:


in your application forms or code.


  • Tung Ngo
    Thanks Mariano, This approach does not work in my case, because the code, which uses HttpContext.Current.Session is in a third party dll.
  • You must to post comments
Showing 2 results
Your Answer
Post as a guest by filling out the fields below or if you already have an account.
File Name Size
There are currently no files uploaded.
Maximum number of files 1, maximum file size 3.9MB.
Supported file formats: zip pdf gif jpg bmp png cs vb theme json