[英]ASP.NET web form application User.Identity.Name not working in IIS
I am using ASP.NET web form application and trying to access User.Identity.Name in one of the page.我正在使用 ASP.NET Web 表单应用程序并尝试在其中一个页面中访问 User.Identity.Name。
However, it is working fine in VS but returns blank in IIS.但是,它在 VS 中运行良好,但在 IIS 中返回空白。
Most likely you are using the correct code within your application, but the configuration file is not set up for Windows Authentication.很可能您在应用程序中使用了正确的代码,但配置文件未针对 Windows 身份验证进行设置。
Make sure these portions are within your web.config file确保这些部分在您的 web.config 文件中
<configuration>
<system.web>
<authentication mode="Windows" />
<authorization>
<deny users="?"/> <!-- Require everyone to log in -->
<!-- add specific allow deny for users and roles here -->
</authorization>
</system.web>
</configuration>
Once these elements are in place, you can access the logged in user information一旦这些元素到位,您就可以访问登录的用户信息
// this will be in form Domain\Username
string UserIdentity = User.Identity.Name;
// or we can split and grab the second element
string[] DomainAndUser = User.Identity.Name.split('\\');
string UserDomain = DomainAndUser[0];
strung UserName = DomainAndUser[1];
MS: how to implement Windows Authentication MS:如何实现 Windows 身份验证
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.