Can System.Web.HttpContext.Current.User.Identity.Name call fail in Session_Start in asp.net webforms app with windows authentication?

I inherited an app with the code below (in global.asax.cs).

The application uses Windows authentication, i.e. web.config contains <authentication mode = "windows"/>. Also only authenticated users are allowed any page.

I wonder why the try/catch block was added. The person who added the code is not available. I assume that at one point it must have failed and the person added the try/catch to get around the error. It might also be leftover code after trying stuff – the previous developer forgot to remove the statement.

void Session_Start(object sender, EventArgs e) {   // Code that runs when a new session is started   string name = "";   try   {     name = System.Web.HttpContext.Current.User.Identity.Name;    }   catch   {   }   Logger.Log.Debug("Session_Start - " + name);  } 
Add Comment
0 Answer(s)

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.