我有一个Intranet网站,我可以在本地计算机上运行时获取用户的身份值.
System.Web.HttpContext.Current.User.Identity.Name.ToString().Substring(3)
但是当我在IIS 8.5上部署它时,它发现它是空白的.
请帮我理解我哪里错了?
对于模拟,我们必须使用特定的用户名和密码.
Web.config文件:
<system.web> <authentication mode="Windows" /> <customErrors mode="RemoteOnly" defaultRedirect="~/Pages/Error/Error.aspx" > <error statusCode="404" redirect="~/Pages/Error/404.aspx" /> </customErrors> <identity impersonate="true" userName="user1" password="pass1" /> </system.web> <system.webServer> <modules runAllManagedModulesForAllRequests="true" /> <validation validateIntegratedModeConfiguration="false" /> </system.webServer>
IIS设置:
Windows authentication - Enabled Impersonation - Enabled Rest all disabled. Default app pool - Integrated mode.
解决方法
IIS设置应如下所示:
+------------------------------------+ | Authentication | +------------------------------------+ Name Status ------------------------ -------- Anonymous Authentication Disabled ---+ ASP.NET Impersonation Enabled | Basic Authentication Enabled |__ Both are important Digest Authentication Disabled | Forms Authentication Disabled | Windows Authentication Enabled ---+
使用User.Identity.Name获取登录用户和test like this:
protected void Page_Load(object sender,EventArgs e) { if (User.Identity.IsAuthenticated) { Page.Title = "Home page for " + User.Identity.Name; } else { Page.Title = "Home page for guest user."; } }