Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to implement User.Identity.Name in Global.asax on a new web application

Tags:

c#

asp.net

In Visual Studio, I've created an entirely new ASP.NET Web Forms Application using their provided template.

I've done nothing to the code that VS auto-generates except add the following to Global.asax.cs:

string myself = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
string me = User.Identity.Name;

String myself stores my current windows logon ID successfully. But string me is null, because when I debug, User is null. However, Visual Studio shows no errors before debugging.

How do I get the proper value for string me using User.Identity.Name?

like image 382
Krondorian Avatar asked Aug 16 '13 22:08

Krondorian


1 Answers

Input code in Session_Start :

void Session_Start(object sender, EventArgs e) 
{
    string myself = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
    string me = User.Identity.Name;
    Response.Write("myself:" + myself + "<br>me:" + me);
}
like image 63
Samiey Mehdi Avatar answered Nov 15 '22 05:11

Samiey Mehdi