0

我有以下代码:

    protected void Page_Load(object sender, EventArgs e)
    {
        string infors = "";
        System.Security.Principal.WindowsIdentity usr = System.Security.Principal.WindowsIdentity.GetCurrent();
        infors += "Authentication Type: " + usr.AuthenticationType + "<br>";
        infors += "Name: " + usr.Name + "<br>";
        infors += "IsAnonymous: " + usr.IsAnonymous + "<br>";
        infors += "IsAuthenticated: " + usr.IsAuthenticated + "<br>";
        infors += "IsGuest: " + usr.IsGuest + "<br>";
        infors += "IsSystem: " + usr.IsSystem + "<br>";
        infors += "Token: " + usr.Token.ToString() + "<br>";

        Label1.Text = infors;
    }

Name但是,它一直在给我错误的信息

身份验证类型:NTLM
名称:SECTOR_A\管理员
匿名:错误
IsAuthenticated: 真
IsGuest:错误
是系统:假
代币:564

我的 IIS 设置为:

匿名身份验证 - 已禁用
ASP.NET 模拟 - 已启用
基本身份验证 - 已启用
Windows 身份验证 - 已启用

我什至通过设置来更改 IE 设置,Prompt for user name and password如下所示

在此处输入图像描述

====== 但是 ======

虽然我在打开 Web 应用程序时在弹出的登录消息中输入了域用户名和密码,但它没有给我正确的Name部分,应该是SECTOR_HQ\Jack.

所以我想问一下我的代码和配置中是否缺少任何东西。

====== 添加了 Web.config ======

<configuration>

    <system.web>
        <compilation debug="true" targetFramework="4.0" />

    </system.web>

</configuration>

====== 应用程序池信息 ======

.NET 框架版本:v4.0
托管管道模式:经典
身份:ApplicationPoolIdentity
4

1 回答 1

0

尝试在您的配置中添加身份验证部分:

 <system.web>
    ...
    <authentication mode="Windows"/>
    <identity impersonate="true"/>
    ...
 </system.web>

在这里您可以找到更多详细信息:

http://msdn.microsoft.com/en-us/library/ff647405.aspx

于 2012-12-27T09:25:53.927 回答