繁体   English   中英

ASP.NET Web 表单应用程序 User.Identity.Name 在 IIS 中不起作用

[英]ASP.NET web form application User.Identity.Name not working in IIS

我正在使用 ASP.NET Web 表单应用程序并尝试在其中一个页面中访问 User.Identity.Name。

但是,它在 VS 中运行良好,但在 IIS 中返回空白。

很可能您在应用程序中使用了正确的代码,但配置文件未针对 Windows 身份验证进行设置。

确保这些部分在您的 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>

一旦这些元素到位,您就可以访问登录的用户信息

// 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:如何实现 Windows 身份验证

ASP.NET 上的 Scott Gu 博客

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM