Global.asax.cs and Session[]

Discussion in 'ASP .Net' started by Just D, Dec 12, 2007.

  1. Just D

    Just D Guest

    Does anybody have any idea why we were able to get Session[] in
    Global.asax.cs in .NET 1.1 and the same code became unworkable in .NET 2.0?
    The code is compilable but the app complains when gets to this point that
    Session[] is not available in current context. Why?

    Just D.
    Just D, Dec 12, 2007
    #1
    1. Advertising

  2. Hello Just,

    Any source code demonstrating this problem? Because as I know there is few
    of foretellers

    ---
    WBR,
    Michael Nemtsev [.NET/C# MVP] :: blog: http://spaces.live.com/laflour

    "The greatest danger for most of us is not that our aim is too high and we
    miss it, but that it is too low and we reach it" (c) Michelangelo


    JD> Does anybody have any idea why we were able to get Session[] in
    JD> Global.asax.cs in .NET 1.1 and the same code became unworkable in
    JD> .NET 2.0? The code is compilable but the app complains when gets to
    JD> this point that Session[] is not available in current context. Why?
    JD>
    JD> Just D.
    JD>
    Michael Nemtsev [MVP], Dec 12, 2007
    #2
    1. Advertising

  3. You haven't described *where* in global.asax that you are trying to get
    Session data, so we can ony guess.
    -- Peter
    Site: http://www.eggheadcafe.com
    UnBlog: http://petesbloggerama.blogspot.com
    MetaFinder: http://www.blogmetafinder.com


    "Just D" wrote:

    > Does anybody have any idea why we were able to get Session[] in
    > Global.asax.cs in .NET 1.1 and the same code became unworkable in .NET 2.0?
    > The code is compilable but the app complains when gets to this point that
    > Session[] is not available in current context. Why?
    >
    > Just D.
    >
    >
    >
    Peter Bromberg [C# MVP], Dec 12, 2007
    #3
  4. Just D

    Just D Guest

    Peter,

    That's easy. I'm not calling Session[] from Application_Start before it was
    created for sure. :) The code I wrote about is located inside protected void
    Application_Error(Object sender, EventArgs e) and it was working for several
    years with .NET 1.1. After I switched to 2.0 the same code stopped working.
    Although the code is compilable it returns a run-time error when I try to
    get this:

    try
    {
    //session = (DxSession)Context.Session["Session"];
    //session = (DxSession)HttpContext.Current.Session["Session"];
    session = (DxSession)Session["Session"];
    }
    catch
    {
    return;
    }

    I also tried these two calls with the same result. I saw these advices on
    the Internet.
    session = (DxSession)Context.Session["Session"];
    session = (DxSession)HttpContext.Current.Session["Session"];

    Just D.


    "Peter Bromberg [C# MVP]" <> wrote in message
    news:...
    > You haven't described *where* in global.asax that you are trying to get
    > Session data, so we can ony guess.
    > -- Peter
    > Site: http://www.eggheadcafe.com
    > UnBlog: http://petesbloggerama.blogspot.com
    > MetaFinder: http://www.blogmetafinder.com
    >
    >
    > "Just D" wrote:
    >
    >> Does anybody have any idea why we were able to get Session[] in
    >> Global.asax.cs in .NET 1.1 and the same code became unworkable in .NET
    >> 2.0?
    >> The code is compilable but the app complains when gets to this point that
    >> Session[] is not available in current context. Why?
    >>
    >> Just D.
    >>
    >>
    >>
    Just D, Dec 12, 2007
    #4
    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. VSK
    Replies:
    1
    Views:
    765
    Alvin Bruney
    Jul 29, 2003
  2. Daniel Bass
    Replies:
    2
    Views:
    6,856
    Daniel Bass
    Dec 31, 2003
  3. 2obvious

    no global constants in global.asax?

    2obvious, Sep 4, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    1,794
  4. =?Utf-8?B?YmNoYXJsZXM=?=

    global.asax and global.asax.cs

    =?Utf-8?B?YmNoYXJsZXM=?=, Oct 4, 2004, in forum: ASP .Net
    Replies:
    5
    Views:
    797
    =?Utf-8?B?YmNoYXJsZXM=?=
    Oct 5, 2004
  5. Mark Rae

    Global.asax / Global.asax.cs in v2

    Mark Rae, May 23, 2006, in forum: ASP .Net
    Replies:
    6
    Views:
    3,136
    Mark Rae
    May 23, 2006
Loading...

Share This Page