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
?
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);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With