Without routing, HttpContext.Current.Session is HttpContext.Current.Session , so I know that StateServer works. When I forward my requests, HttpContext.Current.Session null on the routed page. I am using .NET 3.5 sp1 on IIS 7.0 without MVC previews. It seems that AcquireRequestState never starts when using routes, so the session variable is not created or populated.
When I try to access session variables, I get this error:
base {System.Runtime.InteropServices.ExternalException} = {"Session state can only be used when enableSessionState is set to true, either in a configuration file or in the Page directive. Please also make sure that System.Web.SessionStateModule or a custom session state module is included in the <configuration>.
During debugging, I also get an error that HttpContext.Current.Session not available in this context.
-
My web.config looks like this:
<configuration> ... <system.web> <pages enableSessionState="true"> <controls> ... </controls> </pages> ... </system.web> <sessionState cookieless="AutoDetect" mode="StateServer" timeout="22" /> ... </configuration>
Here's the implementation of IRouteHandler:
public class WebPageRouteHandler : IRouteHandler, IRequiresSessionState { public string m_VirtualPath { get; private set; } public bool m_CheckPhysicalUrlAccess { get; set; } public WebPageRouteHandler(string virtualPath) : this(virtualPath, false) { } public WebPageRouteHandler(string virtualPath, bool checkPhysicalUrlAccess) { m_VirtualPath = virtualPath; m_CheckPhysicalUrlAccess = checkPhysicalUrlAccess; } public IHttpHandler GetHttpHandler(RequestContext requestContext) { if (m_CheckPhysicalUrlAccess && !UrlAuthorizationModule.CheckUrlAccessForPrincipal( m_VirtualPath, requestContext.HttpContext.User, requestContext.HttpContext.Request.HttpMethod)) { throw new SecurityException(); } string var = String.Empty; foreach (var value in requestContext.RouteData.Values) { requestContext.HttpContext.Items[value.Key] = value.Value; } Page page = BuildManager.CreateInstanceFromVirtualPath( m_VirtualPath, typeof(Page)) as Page;
I also tried putting EnableSessionState="True" at the top of the aspx pages, but still nothing.
Any ideas? Should I write another HttpRequestHandler that implements IRequiresSessionState ?
Thank.
Loki Oct 20 '08 at 11:03 2008-10-20 11:03
source share