带有模拟的ASP.NET Windows身份验证

时间:2015-04-28 10:55:53

标签: c# asp.net windows-authentication

我想为我的ASP.NET Intranet应用程序启用Windows身份验证。 为此,我在web.config文件中执行了以下操作。

<system.web>
 <authentication mode="Windows" >

    </authentication>
    <authorization>
      <deny users="?"/>
    </authorization>
    <identity impersonate="true" userName="domain\myusername" password="mypwd" />
</system.web>

我正在尝试在我的网页中访问经过身份验证的用户名

HttpContext.Current.User.Identity.Name

它会拒绝接入&#34;错误信息。

1 个答案:

答案 0 :(得分:3)

尝试使用WindowsIdentity.NameWindowsIdentity.GetCurrent().Name代替HttpContext.Current.User.Identity.Name

就向Claim添加角色而言,您可以在某些代码的帮助下添加角色。这些链接可能对您有所帮助:

Creating ClaimIdentity Object

Claim Based Security in C#

希望这有帮助。