【问题标题】:ASP.NET windows authentication with impersonation带有模拟的 ASP.NET Windows 身份验证
【发布时间】:2015-04-28 10:55:53
【问题描述】:

我想为我的 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

它会抛出“拒绝访问”错误消息。

【问题讨论】:

  • 那么您是否必须在您的网页中获取 Impersonated name ?
  • 不,我没有在这里获得任何用户名,这会引发访问被拒绝错误。当我删除授权标签时,我可以访问我的页面,但无法获取模拟用户。
  • 尝试使用WindowsIdentity.NameWindowsIdentity.GetCurrent().Name 而不是HttpContext.Current.User.Identity.Name
  • 嗨,WindowsIdentity.GetCurrent().Name 工作正常。谢谢(你的)信息。我可以在 SQL 表中的 UserClaims 中添加一些角色吗??
  • 可能是的。检查我的答案。

标签: c# asp.net windows-authentication


【解决方案1】:

尝试使用WindowsIdentity.NameWindowsIdentity.GetCurrent().Name 而不是HttpContext.Current.User.Identity.Name

至于为Claim添加角色,可以借助一些代码来添加。这些链接可能会对您有所帮助:

Creating ClaimIdentity Object

Claim Based Security in C#

希望这会有所帮助。

【讨论】:

    猜你喜欢
    • 2014-09-08
    • 1970-01-01
    • 2010-11-27
    • 2011-06-08
    • 2014-03-01
    • 2011-11-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多