views:

21

answers:

1

When I am debugging an application in ASP.NET, after about ~5 minutes I get a NullRefEx coming from global.asax.cs regarding:

protected void Session_Start(Object sender, EventArgs e)
        {
            WindowsIdentity identity = null;
            identity = (WindowsIdentity)(Context.User.Identity);
...

Context is Null at this point. I am a noob in ASP.NET with regards to Global.asax.cs. This code was written by another developer.

EDIT: This is the code with HttpContext...

    protected void Session_Start(Object sender, EventArgs e)
    {
    WindowsIdentity identity = null;
    identity = (WindowsIdentity)(HttpContext.Current.User.Identity);
A: 

Try:

identity = (WindowsIdentity)(HttpContext.Current.User.Identity); 

edited to be more clear (I hope...)

Ray
Can you elaborate on what the difference here please?
P.Brian.Mackey
UPDATE: The problem still exists with HttpContext.
P.Brian.Mackey
I just tried it on my site and it works for me. Can you post your revised code? I will edit my answer to more clearly show what I meant.
Ray
I added the updated code. Its practically identical. The problem ONLY occurs after about ~5 minutes. There is no issue at startup.
P.Brian.Mackey
Weird. So in your first (startup) session, it works. But then after 5 minutes or so, you start a new session and it fails? Is it HttpContext.Current that is null at this point? Or could it be something else?
Ray
Yes thats what's happening. I don't know why i'm starting a new session so early either. HttpContext is null at this point, it could be something higher up the chain, but I am not sure.
P.Brian.Mackey
The new session is probably caused by your timeout value of 1. Is this new session another page request from the same browser, or is it a new browser window, or something else entirely? Is there anything in the call stack that might be helpful?
Ray
I'm giving up on this for now. This application was built in visual studio 2000, problems started in the conversion to 2008. Solution is no solution.
P.Brian.Mackey