views:

35

answers:

0

Is it possible to allow access of session state for paths in the integrated web server in visual studio?

In other words, on my local instance of IIS I am able to access session state for "~/path/". When I try to access the same when running under the local developer instance in visual studio for "~/path/" session is always null.

Originally I was not able to access session on my local instance of IIS but when I add the preCondition="managedHandler" attribute for my handler I was then able to access session state. Adding this attribute did not work for my visual studio web server instance.

I did try add the code as described in this SO thread, but that did not work either, I also tried moving the remapping from PostMapRequestHandler to PreRequestHandlerExecute.

It appears to me that requests for paths are being passed through the ASP.net handler on my local IIS server, but they are not on my visual studio instance.

I'd just upgraded my dev box from windows XP/iis 6 to windows 7/iis 7 so I'm fumbling just a bit due to my inexperience with windows 7/iis 7.

Also I've altered the code a bit as it was originally written in the thread I mentioned above, it now looks like the following:

public class PassThruModule : IHttpModule, IRequiresSessionState
{
    public void Init(HttpApplication application)
    {
        application.PreRequestHandlerExecute += this.PostAcquireRequestState;
    }

    private void PostAcquireRequestState(object source, EventArgs e)
    {
        var application = (HttpApplication)source;
        var context = application.Context;

        if (context.Request.RequestType != "POST" || context.Request.Form[HidMktKey] == null)
        {   
            return;
        }

        Debug.WriteLine(context.Request.AppRelativeCurrentExecutionFilePath);

        if (!(application.Context.Handler is IReadOnlySessionState || application.Context.Handler is IRequiresSessionState))
        {
            application.Context.Handler = new SessionHandler(application.Context.Handler);
        }

        var sessionHandler = HttpContext.Current.Handler as SessionHandler;

        if (sessionHandler != null)
        {
            context.Handler = sessionHandler.OriginalHandler;
        }

       /* .... Do stuff that requires session state .... */
    }
}

public class SessionHandler : IHttpHandler, IRequiresSessionState
{
    public SessionHandler(IHttpHandler originalHandler)
    {
        this.OriginalHandler = originalHandler;
    }

    public bool IsReusable
    {
        get { return false; }
    }

    internal IHttpHandler OriginalHandler { get; private set; }

    public void ProcessRequest(HttpContext context)
    {
        throw new InvalidOperationException("Session Handler can not process requests.");
    }

}