如何实现User.Identity.Name在Global.asax中一个新的Web应用程序 [英] How to implement User.Identity.Name in Global.asax on a new web application
问题描述
在Visual Studio中,我创建使用他们提供的模板了一个全新的ASP.NET Web窗体应用程序。
In Visual Studio, I've created an entirely new ASP.NET Web Forms Application using their provided template.
我还没有做什么到code,它VS自动生成除了添加如下的Global.asax.cs
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;
字符串存储自己当前的Windows成功登录ID。但我的字符串为空,因为当我调试,用户为空。但是,Visual Studio中显示调试之前没有错误。
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.
我如何得到正确的值,我使用User.Identity.Name字符串?
How do I get the proper value for string me using User.Identity.Name?
推荐答案
输入code中的在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);
}
这篇关于如何实现User.Identity.Name在Global.asax中一个新的Web应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!