c# – 无法获取当前用户标识值
发布时间:2020-12-15 08:10:40 所属栏目:百科 来源:网络整理
导读:我有一个Intranet网站,我可以在本地计算机上运行时获取用户的身份值. System.Web.HttpContext.Current.User.Identity.Name.ToString().Substring(3) 但是当我在IIS 8.5上部署它时,它发现它是空白的. 请帮我理解我哪里错了? 对于模拟,我们必须使用特定的用户
我有一个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."; } } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |