Session not available in VirtualPathProvider
-
Hello guys, I'm struggling a problem now for some days. Hopefully one of you guys can help me out with that. I wrote my own VirtualPathProvider and VirtualPathFile to make it possible to load different pages from different locations. It works very good. But now I need to load the pages from different locations depending on a value stored in the session. The time when VirtualPathprovider is invoked the Session object is not available or lets say it's available but null. Now I found out that the session object is filled when the AcquireSessionState event is invoked, but thats to late for me because the action of loading the page already passed. So now I want to create the session by my own before the AcquireSessionState is invoked. But I don't know how to fill the session object by my own. Does anybody can help me with this problem? Or has anybody a better idea then filling the session object by my own. Thanks a lot for any input Oliver
-
Hello guys, I'm struggling a problem now for some days. Hopefully one of you guys can help me out with that. I wrote my own VirtualPathProvider and VirtualPathFile to make it possible to load different pages from different locations. It works very good. But now I need to load the pages from different locations depending on a value stored in the session. The time when VirtualPathprovider is invoked the Session object is not available or lets say it's available but null. Now I found out that the session object is filled when the AcquireSessionState event is invoked, but thats to late for me because the action of loading the page already passed. So now I want to create the session by my own before the AcquireSessionState is invoked. But I don't know how to fill the session object by my own. Does anybody can help me with this problem? Or has anybody a better idea then filling the session object by my own. Thanks a lot for any input Oliver
A thought!..Can you use cookieContainer!! or HttpApplication instance!!
-
A thought!..Can you use cookieContainer!! or HttpApplication instance!!
Hi, Thanks for the input, but I use cookieless sessions. I tried to retrieve session data from different locations: HttpContext.Current.Session - null at this time HttpContext.Current.ApplicationInstance.Session - null at this time as well I guess thats because the AcquireSessionState is called later on - where the session object is filled. What I want to do now is to try initialize the Session earlier, but I don't know if it's possible. Thanks Oliver
-
A thought!..Can you use cookieContainer!! or HttpApplication instance!!
Hi peacefulmember, I have to apologize. I use cookies without my knowledge :-) Now that I know that I use cookies I found out that there is a cookie in which the session id is stored. I save now the value which I wanted to store in the session also in the cache with following statement:
Cache[Session.SessionID + "_MyKey"] = Value;
The difference to just saving it in the session is that the cache is available every time and the cookies are already present at the time I need to get the value. So in my VirtualFile I added following code to retrieve the value again:if (HttpContext.Current.Request.Cookies["ASP.NET_SessionId"] != null) { value = (String)System.Web.Hosting.HostingEnvironment.Cache[HttpContext.Current.Request.Cookies["ASP.NET_SessionId"].Value + "_MyKey"]; }
That solved the problem for me. It's kind of a workaround. I would have preferred the "Session-Solution" but as the Session is not filled that time I have to solve it this way. Thanks Oliver