簡體   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