Obtaining Session State in a IHttpModule or IHttpHandler when a request is for a static fileRSS

1 reply

Last post Apr 12, 2013 10:37 AM by Perkinsville

  • Obtaining Session State in a IHttpModule or IHttpHandler when a request is for a static file

    Mar 09, 2013 06:05 AM|AdrianGould|LINK

    Hi.

    We are developing a IHttpModule that requires session state to be available when the pipeline reaches the Process Request stage.

    We use the following :-

    application.PostMapRequestHandler += new EventHandler(SetSessionStateBehavior);

    and in this method we apply the following:-

    application.Context.SetSessionStateBehavior(SessionStateBehavior.Required);

    Which works as expected.

    However, if the request is for a static file, i.e website/image.gif then we assume the static file handler takes over our process request is never reached, so we have replaced the handler for our own  dummy handler that implements the interface IRequiresSessionState, as follows:-

    application.Context.RemapHandler(new PlaceHolderHandler());

    this works but session state is not available for requests that reference a static files.

    Can anyone help resolve this issue. We need a way of forcing session state to be available, regardless of the request URL.

    Regards

    Adrian.

  • Re: Obtaining Session State in a IHttpModule or IHttpHandler when a request is for a static file

    Apr 12, 2013 10:37 AM|Perkinsville|LINK

    Hi,

    The ASP.NET Handler is not used when requests to static files are made, so that code is likely not executed.

    You might consider adding a global handler (Path = *) that is configured same as an ASPX file (Path = *.aspx).

    Might work, HTH, Benjamin