I've got a problem with HttpContext.Current.Session. I try to enable session state on my application. I did a few things:
- add to my web.config:
<sessionState cookieless="UseCookies" regenerateExpiredSessionId="true" mode="InProc" timeout="20"/>
I want to use cookies too so I set up cookieless="UseCookies".
After that I added:
<pages enableSessionState="true">
this page section isn't closed because contains a few namespaces like that:
<pages enableSessionState="true"> <namespaces> <add namespace="..."/> </namespaces> </pages>
- In my Global.asax.vb I created two event handlers:
Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs) ' Fires when the session is started End Sub
and
Sub Session_End(ByVal sender As Object, ByVal e As EventArgs) ' Fires when the session ends End Sub
- I created some c# class which will be management my session:
public class MySession { public static void Add(string key, object value) { if (HttpContext.Current.Session != null && (HttpContext.Current.Session.Keys == null || (HttpContext.Current.Session.Keys != null && HttpContext.Current.Session[key] == null))) { HttpContext.Current.Session.Add(key, value); } } public static void Remove(string key) { ... } public static void Update(string key, object value) { ... } public static object GetValue(string key) { ... } }
It's all what I did in code and yeah - my app using vb and c# too. So when I try to use MySession.Add(someKey, someValue) always I've got a HttpContext.Current.Session == null.
It's my first time when I try turn on a session in app so I need help with this. I was looking for any solution into google but they either didn't work or they were not for me.
Any idea?
HttpContext.Current.Session != nullis true or false? - Mohsin Mehmood