SessionState in HttpModule problem (2.0)

Discussion in 'ASP .Net' started by Tomasz, Apr 12, 2007.

  1. Tomasz

    Tomasz Guest

    Hello Developers,

    I have an interesting problem. How, or when can I access SessionState from
    It seems that session state is only available when *.aspx page is requested.
    It is not available for other resource types like *.gif files etc.

    Is there any way I can force session state to load, even when it is not
    *.aspx page being requested?

    Thank you,
    Tomasz J
    Tomasz, Apr 12, 2007
    1. Advertisements

  2. Tomasz

    Aidy Guest

    It is off by default, change your declaration

    public class MyClass : IHttpHandler, IRequiresSessionState
    Aidy, Apr 12, 2007
    1. Advertisements

  3. Tomasz

    Tomasz Guest

    Thanks, but I am talking about HttpModule, not HttpHandler.
    Tomasz, Apr 12, 2007
  4. Hi Tomasz,

    By default, *.gif files are served by IIS, not the aspnet_isapi.dll (like
    *.aspx); and the Session State is loaded by SessionStateModule, which is a
    built-in HttpModule, you can find it's configured in system-wide web.config
    such as:

    <add name="OutputCache"
    type="System.Web.Caching.OutputCacheModule" />
    <add name="Session"
    type="System.Web.SessionState.SessionStateModule" />
    <add name="WindowsAuthentication"
    type="System.Web.Security.WindowsAuthenticationModule" />


    If you need to load session state when user is requesting *.gif files, you
    must configure IIS to serve *.gif files via aspnet_isapi.dll; however,
    please note serving static content via aspnet_isapi.dll is not effective as
    serving via IIS.

    Hope this helps.

    Walter Wang (, remove 'online.')
    Microsoft Online Community Support

    Get notification to my posts through email? Please refer to
    ications. If you are using Outlook Express, please make sure you clear the
    check box "Tools/Options/Read: Get 300 headers at a time" to see your reply

    Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
    where an initial response from the community or a Microsoft Support
    Engineer within 1 business day is acceptable. Please note that each follow
    up response may take approximately 2 business days as the support
    professional working with you may need further investigation to reach the
    most efficient resolution. The offering is not appropriate for situations
    that require urgent, real-time or phone-based interactions or complex
    project analysis and dump analysis issues. Issues of this nature are best
    handled working with a dedicated Microsoft Support Engineer by contacting
    Microsoft Customer Support Services (CSS) at

    This posting is provided "AS IS" with no warranties, and confers no rights.
    Walter Wang [MSFT], Apr 13, 2007
  5. Tomasz

    Tomasz J Guest

    Thank you Walter, but I am not quite sure I understand.
    It looks like those "static content" requests, somehow, involve
    aspnet_isapi.dll. All the events like BeginRequest, AuthorizeRequest or
    AcquireRequestState fire. It is just that the HttpContext.Current.Session is

    What I am trying to develop is a special kind of rewrite engine. It must
    have access to the session state and I cannot modify system-wide web.config
    settings - the application is supposed to work in shared hosting

    Do you think it can be done using HttpHandler? If so, where/when do I have
    to call Context.RewritePath() method?

    Thank you,

    Tomasz J
    Tomasz J, Apr 13, 2007
  6. Tomasz

    Tomasz J Guest

    I just came across this great post by Mike Volodarsky, IIS Core Server /
    ASP.NET Runtime Program Manager

    It looks like it is a known issue and whether or not session state is
    available is actually decided... by the SessionStateModule itself!

    Tomasz J
    Tomasz J, Apr 14, 2007
  7. Hi Tomasz,

    Thank you for sharing the URL and I'm glad you've found the

    Walter Wang (, remove 'online.')
    Microsoft Online Community Support

    When responding to posts, please "Reply to Group" via your newsreader so
    that others may learn and benefit from your issue.

    This posting is provided "AS IS" with no warranties, and confers no rights.
    Walter Wang [MSFT], Apr 16, 2007
  8. Tomasz

    Tomasz J Guest

    Hello Walter,

    Here is a brief description of the solution I implemented.

    In order to force session state to load, the current Context.Handler,
    usually DefaultHttpHandler, has to be replaced in the PostMapRequestHandler
    event by some other handler, implementing IRequiresSessionState. To be safe,
    my dummy handler implementing IRequiresSessionState also carries a reference
    to the original handler, and I swap it back in the PostAcquireRequestState
    event, once the dummy handler fulfilled its mission between those two


    Tomasz J
    Tomasz J, Apr 16, 2007
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.