我有一个 Intranet 网站,在本地机器上运行时,我可以在其中获取用户的身份值。
System.Web.HttpContext.Current.User.Identity.Name.ToString().Substring(3)
但是当我在 IIS 8.5 上部署它时,它发现它是空白的。
请帮助我了解我哪里出错了?
对于模拟,我们必须使用特定的用户名和密码。
网络配置:
<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.";
}
}
关于c# - 无法获取当前用户标识值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48705441/