开发者

NullReferenceException in Global.asax when referencing Context.User.Identity in Session_Start

开发者 https://www.devze.com 2023-01-18 12:08 出处:网络
When I am debugging an application in ASP.NET, after about ~5 minutes I get a NullR开发者_如何学运维efEx coming from global.asax.cs regarding:

When I am debugging an application in ASP.NET, after about ~5 minutes I get a NullR开发者_如何学运维efEx 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);


Try:

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

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

0

精彩评论

暂无评论...
验证码 换一张
取 消