Hello,
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.
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:
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.
HTH
Best,
Luca
Hi Chris,
I added an example.
You have to change the namespace.
With the new web.config entry you overwritte the default handler for wx.
I choose the second approach from Luca’s post and store the HttpContext.Current.Session in Application.Session.AspNetSession.
Best,
Jens
Hi , can you provide some more info on adding the namespace, where should I put it.
When I add it I get lots of errors from all the forms in the application as various events are missing, i guess its intefering with the normal wisej namespace.
Also
Where do you put this line in the webconfig , the handlers I am guessing , but does it replace the normal wisej handler ?
<add name="wisej" verb="*" path="*.wx" type="Wisej.Core.HttpHandlerRequiresSession, [Assembly Name]"/> Assembly name I presume is the fully qualified name of your project assembly ? I am working in vb.net
Hi Tung.
Just out of curiosity, is it possible to know the name of this third party application framework you mention?
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:
Application.Session.UserId
Application.Session.UserName
in your application forms or code.
Mariano