Session object is NULL in HTTPModule

Discussion in 'ASP .Net' started by =?Utf-8?B?TWlndWVs?=, Aug 25, 2005.

  1. ey,
    I m trying to make a new httpmodule but the session object is null. I m
    implementing IReadOnlySessionState but it keep on being null.

    I m novice in this enviroment, does anybody know what's happening?

    thanks

    Miguel
     
    =?Utf-8?B?TWlndWVs?=, Aug 25, 2005
    #1
    1. Advertising

  2. =?Utf-8?B?TWlndWVs?=

    Karl Seguin Guest

    It's likely a timing issue. Session isn't available until the
    AcquireRequestState event.

    Try hooking after this, such as the PreRequestHandlerExecute event

    Karl

    --
    MY ASP.Net tutorials
    http://www.openmymind.net/ - New and Improved (yes, the popup is annoying)
    http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
    come!)


    "Miguel" <> wrote in message
    news:...
    > ey,
    > I m trying to make a new httpmodule but the session object is null. I m
    > implementing IReadOnlySessionState but it keep on being null.
    >
    > I m novice in this enviroment, does anybody know what's happening?
    >
    > thanks
    >
    > Miguel
     
    Karl Seguin, Aug 25, 2005
    #2
    1. Advertising

  3. thank you karl,

    buff, it doesn't work, I think I am doing what you have said but I dont get
    the session: context.PreRequestHandlerExecute += (new EventHandler
    this.Application_AuthenticateRequest));.

    any ideas? I am a little bit lost :-(

    thanks again

    here is the source code:

    public class SetIdentity : IHttpModule, IReadOnlySessionState
    {
    public void Init(HttpApplication context)
    {
    context.PreRequestHandlerExecute += (new EventHandler
    this.Application_AuthenticateRequest));
    }

    private void Application_AuthenticateRequest(object source, EventArgs e)
    {
    HttpApplication application = (HttpApplication)source;

    HttpContext context = application.Context;
    HttpSessionState session = context.Session;

    String cookieValue = "No session";
    if (session != null) cookieValue = session.SessionID;
    // Put it into a cookie
    HttpCookie hc = new
    HttpCookie("SessionSharePoint", cookieValue);
    hc.Expires = DateTime.Now.AddMinutes(20);

    // Add it to the cookies collection
    context.Response.Cookies.Add(hc);


    }
    public void Dispose()
    {
    }


    }


    "Karl Seguin" wrote:

    > It's likely a timing issue. Session isn't available until the
    > AcquireRequestState event.
    >
    > Try hooking after this, such as the PreRequestHandlerExecute event
    >
    > Karl
    >
    > --
    > MY ASP.Net tutorials
    > http://www.openmymind.net/ - New and Improved (yes, the popup is annoying)
    > http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
    > come!)
    >
    >
    > "Miguel" <> wrote in message
    > news:...
    > > ey,
    > > I m trying to make a new httpmodule but the session object is null. I m
    > > implementing IReadOnlySessionState but it keep on being null.
    > >
    > > I m novice in this enviroment, does anybody know what's happening?
    > >
    > > thanks
    > >
    > > Miguel

    >
    >
    >
     
    =?Utf-8?B?TWlndWVs?=, Aug 25, 2005
    #3
  4. =?Utf-8?B?TWlndWVs?=

    Karl Seguin Guest

    Your code works fine for me. session isn't null and cookie was being set...

    I'm not the only one recommending my approach:
    http://channel9.msdn.com/ShowPost.aspx?PostID=1498

    but, you don't seem to be the only one having problems:
    http://weblogs.asp.net/acampbell/archive/2004/12/08/277929.aspx

    Perhaps you can contact Alex and see if he ever solved his problem?

    karl

    --
    MY ASP.Net tutorials
    http://www.openmymind.net/ - New and Improved (yes, the popup is
    annoying)
    http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
    come!)
    "Miguel" <> wrote in message
    news:...
    > thank you karl,
    >
    > buff, it doesn't work, I think I am doing what you have said but I dont
    > get
    > the session: context.PreRequestHandlerExecute += (new EventHandler
    > this.Application_AuthenticateRequest));.
    >
    > any ideas? I am a little bit lost :-(
    >
    > thanks again
    >
    > here is the source code:
    >
    > public class SetIdentity : IHttpModule, IReadOnlySessionState
    > {
    > public void Init(HttpApplication context)
    > {
    > context.PreRequestHandlerExecute += (new EventHandler
    > this.Application_AuthenticateRequest));
    > }
    >
    > private void Application_AuthenticateRequest(object source, EventArgs e)
    > {
    > HttpApplication application = (HttpApplication)source;
    >
    > HttpContext context = application.Context;
    > HttpSessionState session = context.Session;
    >
    > String cookieValue = "No session";
    > if (session != null) cookieValue = session.SessionID;
    > // Put it into a cookie
    > HttpCookie hc = new
    > HttpCookie("SessionSharePoint", cookieValue);
    > hc.Expires = DateTime.Now.AddMinutes(20);
    >
    > // Add it to the cookies collection
    > context.Response.Cookies.Add(hc);
    >
    >
    > }
    > public void Dispose()
    > {
    > }
    >
    >
    > }
    >
    >
    > "Karl Seguin" wrote:
    >
    >> It's likely a timing issue. Session isn't available until the
    >> AcquireRequestState event.
    >>
    >> Try hooking after this, such as the PreRequestHandlerExecute event
    >>
    >> Karl
    >>
    >> --
    >> MY ASP.Net tutorials
    >> http://www.openmymind.net/ - New and Improved (yes, the popup is
    >> annoying)
    >> http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
    >> come!)
    >>
    >>
    >> "Miguel" <> wrote in message
    >> news:...
    >> > ey,
    >> > I m trying to make a new httpmodule but the session object is null. I m
    >> > implementing IReadOnlySessionState but it keep on being null.
    >> >
    >> > I m novice in this enviroment, does anybody know what's happening?
    >> >
    >> > thanks
    >> >
    >> > Miguel

    >>
    >>
    >>
     
    Karl Seguin, Aug 25, 2005
    #4
  5. thanks, really helpfull.
    The problem seems not to be easy.

    cheers

    Miguel

    "Karl Seguin" wrote:

    > Your code works fine for me. session isn't null and cookie was being set...
    >
    > I'm not the only one recommending my approach:
    > http://channel9.msdn.com/ShowPost.aspx?PostID=1498
    >
    > but, you don't seem to be the only one having problems:
    > http://weblogs.asp.net/acampbell/archive/2004/12/08/277929.aspx
    >
    > Perhaps you can contact Alex and see if he ever solved his problem?
    >
    > karl
    >
    > --
    > MY ASP.Net tutorials
    > http://www.openmymind.net/ - New and Improved (yes, the popup is
    > annoying)
    > http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
    > come!)
    > "Miguel" <> wrote in message
    > news:...
    > > thank you karl,
    > >
    > > buff, it doesn't work, I think I am doing what you have said but I dont
    > > get
    > > the session: context.PreRequestHandlerExecute += (new EventHandler
    > > this.Application_AuthenticateRequest));.
    > >
    > > any ideas? I am a little bit lost :-(
    > >
    > > thanks again
    > >
    > > here is the source code:
    > >
    > > public class SetIdentity : IHttpModule, IReadOnlySessionState
    > > {
    > > public void Init(HttpApplication context)
    > > {
    > > context.PreRequestHandlerExecute += (new EventHandler
    > > this.Application_AuthenticateRequest));
    > > }
    > >
    > > private void Application_AuthenticateRequest(object source, EventArgs e)
    > > {
    > > HttpApplication application = (HttpApplication)source;
    > >
    > > HttpContext context = application.Context;
    > > HttpSessionState session = context.Session;
    > >
    > > String cookieValue = "No session";
    > > if (session != null) cookieValue = session.SessionID;
    > > // Put it into a cookie
    > > HttpCookie hc = new
    > > HttpCookie("SessionSharePoint", cookieValue);
    > > hc.Expires = DateTime.Now.AddMinutes(20);
    > >
    > > // Add it to the cookies collection
    > > context.Response.Cookies.Add(hc);
    > >
    > >
    > > }
    > > public void Dispose()
    > > {
    > > }
    > >
    > >
    > > }
    > >
    > >
    > > "Karl Seguin" wrote:
    > >
    > >> It's likely a timing issue. Session isn't available until the
    > >> AcquireRequestState event.
    > >>
    > >> Try hooking after this, such as the PreRequestHandlerExecute event
    > >>
    > >> Karl
    > >>
    > >> --
    > >> MY ASP.Net tutorials
    > >> http://www.openmymind.net/ - New and Improved (yes, the popup is
    > >> annoying)
    > >> http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
    > >> come!)
    > >>
    > >>
    > >> "Miguel" <> wrote in message
    > >> news:...
    > >> > ey,
    > >> > I m trying to make a new httpmodule but the session object is null. I m
    > >> > implementing IReadOnlySessionState but it keep on being null.
    > >> >
    > >> > I m novice in this enviroment, does anybody know what's happening?
    > >> >
    > >> > thanks
    > >> >
    > >> > Miguel
    > >>
    > >>
    > >>

    >
    >
    >
     
    =?Utf-8?B?TWlndWVs?=, Aug 26, 2005
    #5
  6. ey karl!

    Know it is working. It was a problem with the web.config. There is a
    parameter to false that must be true and a comment module in charge of the
    sessionState.

    Thank you

    miguel

    "Karl Seguin" wrote:

    > Your code works fine for me. session isn't null and cookie was being set...
    >
    > I'm not the only one recommending my approach:
    > http://channel9.msdn.com/ShowPost.aspx?PostID=1498
    >
    > but, you don't seem to be the only one having problems:
    > http://weblogs.asp.net/acampbell/archive/2004/12/08/277929.aspx
    >
    > Perhaps you can contact Alex and see if he ever solved his problem?
    >
    > karl
    >
    > --
    > MY ASP.Net tutorials
    > http://www.openmymind.net/ - New and Improved (yes, the popup is
    > annoying)
    > http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
    > come!)
    > "Miguel" <> wrote in message
    > news:...
    > > thank you karl,
    > >
    > > buff, it doesn't work, I think I am doing what you have said but I dont
    > > get
    > > the session: context.PreRequestHandlerExecute += (new EventHandler
    > > this.Application_AuthenticateRequest));.
    > >
    > > any ideas? I am a little bit lost :-(
    > >
    > > thanks again
    > >
    > > here is the source code:
    > >
    > > public class SetIdentity : IHttpModule, IReadOnlySessionState
    > > {
    > > public void Init(HttpApplication context)
    > > {
    > > context.PreRequestHandlerExecute += (new EventHandler
    > > this.Application_AuthenticateRequest));
    > > }
    > >
    > > private void Application_AuthenticateRequest(object source, EventArgs e)
    > > {
    > > HttpApplication application = (HttpApplication)source;
    > >
    > > HttpContext context = application.Context;
    > > HttpSessionState session = context.Session;
    > >
    > > String cookieValue = "No session";
    > > if (session != null) cookieValue = session.SessionID;
    > > // Put it into a cookie
    > > HttpCookie hc = new
    > > HttpCookie("SessionSharePoint", cookieValue);
    > > hc.Expires = DateTime.Now.AddMinutes(20);
    > >
    > > // Add it to the cookies collection
    > > context.Response.Cookies.Add(hc);
    > >
    > >
    > > }
    > > public void Dispose()
    > > {
    > > }
    > >
    > >
    > > }
    > >
    > >
    > > "Karl Seguin" wrote:
    > >
    > >> It's likely a timing issue. Session isn't available until the
    > >> AcquireRequestState event.
    > >>
    > >> Try hooking after this, such as the PreRequestHandlerExecute event
    > >>
    > >> Karl
    > >>
    > >> --
    > >> MY ASP.Net tutorials
    > >> http://www.openmymind.net/ - New and Improved (yes, the popup is
    > >> annoying)
    > >> http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
    > >> come!)
    > >>
    > >>
    > >> "Miguel" <> wrote in message
    > >> news:...
    > >> > ey,
    > >> > I m trying to make a new httpmodule but the session object is null. I m
    > >> > implementing IReadOnlySessionState but it keep on being null.
    > >> >
    > >> > I m novice in this enviroment, does anybody know what's happening?
    > >> >
    > >> > thanks
    > >> >
    > >> > Miguel
    > >>
    > >>
    > >>

    >
    >
    >
     
    =?Utf-8?B?TWlndWVs?=, Aug 26, 2005
    #6
  7. =?Utf-8?B?TWlndWVs?=

    argon18

    Joined:
    Oct 27, 2006
    Messages:
    1
    Web.config

    Hi Miguel,
    I know this post was from a while back, but I'm having the same exact issue. What were the lines in the web.config that you changed? Thanks for the clarification!

    -argon
     
    argon18, Oct 27, 2006
    #7
  8. =?Utf-8?B?TWlndWVs?=

    Dennis1210

    Joined:
    Jul 1, 2008
    Messages:
    1
    He means the cookieless attribute of the sessionstate element in your web.config.
     
    Dennis1210, Jul 1, 2008
    #8
  9. =?Utf-8?B?TWlndWVs?=

    marktur

    Joined:
    Aug 23, 2010
    Messages:
    1
    this kind ofthing I think:

    <httpModules>
    <add name="DaoFactoryProvider" type="Capture.DaoProvider.DaoFactoryProvider"/>
    </httpModules>
     
    marktur, Aug 23, 2010
    #9
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?QW5kZXJzIEJvcm5ob2xt?=

    HttpModule session state null for .zip files

    =?Utf-8?B?QW5kZXJzIEJvcm5ob2xt?=, Aug 26, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    612
    Brock Allen
    Aug 29, 2005
  2. Replies:
    16
    Views:
    7,399
    Mike Schilling
    Oct 12, 2005
  3. Replies:
    5
    Views:
    27,236
    Mike Schilling
    Mar 29, 2006
  4. Cirene
    Replies:
    1
    Views:
    836
    Alexey Smirnov
    Jun 9, 2008
  5. putty
    Replies:
    1
    Views:
    270
    putty
    Apr 5, 2005
Loading...

Share This Page