Note that there are some explanatory texts on larger screens.

plurals
  1. POHttpContext.Current.Session is null when routing requests
    primarykey
    data
    text
    <p>Without routing, <code>HttpContext.Current.Session</code> is there so I know that the <code>StateServer</code> is working. When I route my requests, <code>HttpContext.Current.Session</code> is <code>null</code> in the routed page. I am using .NET 3.5 sp1 on IIS 7.0, without the MVC previews. It appears that <code>AcquireRequestState</code> is never fired when using the routes and so the session variable isn't instantiated/filled.</p> <p>When I try to access the Session variables, I get this error:</p> <p><code>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 &lt;configuration&gt;.</code></p> <p>While debugging, I also get the error that the <code>HttpContext.Current.Session</code> is not accessible in that context.</p> <p>--</p> <p>My <code>web.config</code> looks like this:</p> <pre><code>&lt;configuration&gt; ... &lt;system.web&gt; &lt;pages enableSessionState="true"&gt; &lt;controls&gt; ... &lt;/controls&gt; &lt;/pages&gt; ... &lt;/system.web&gt; &lt;sessionState cookieless="AutoDetect" mode="StateServer" timeout="22" /&gt; ... &lt;/configuration&gt; </code></pre> <p>Here's the IRouteHandler implementation:</p> <pre><code>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 &amp;&amp; !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;// IHttpHandler; if (page != null) { return page; } return page; } } </code></pre> <p>I've also tried to put <code>EnableSessionState="True"</code> on the top of the aspx pages but still, nothing.</p> <p>Any insights? Should I write another <code>HttpRequestHandler</code> that implements <code>IRequiresSessionState</code>?</p> <p>Thanks.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload