【问题标题】:Current user with ASP.NET Forms authentication app具有 ASP.NET Forms 身份验证应用程序的当前用户
【发布时间】:2013-05-04 08:18:17
【问题描述】:

我正在尝试在使用 ASP.NET Forms 身份验证的 Web 应用程序中检索当前用户。 但是,System.Security.Principal.WindowsIdentity.GetCurrent().Name 返回 domain\windowsUser,而不是 FormsAuthentication.RedirectFromLoginPage 方法中使用的用户名。 我在我的配置文件中使用表单身份验证:

<authentication mode="Forms">
      <forms loginUrl="Views/Login.aspx" name=".ASPXFORMSAUTH" timeout="1" cookieless="UseUri">
      </forms>
    </authentication>
    <authorization>
      <deny users="?" />
    </authorization>

我还尝试按照 Microsoft 的步骤进行操作,并使用以下 sn-p 检索身份验证票:

    if (Request.IsAuthenticated)
    {
         var ident = User.Identity as FormsIdentity;
        if (ident != null)
        {

            FormsAuthenticationTicket ticket = ident.Ticket;
            var name = ticket.Name;
        }
    }

但是,ident 始终为 null,因为它是 WindowsIdentity 而不是 FormsIdentity。这里有什么问题? 谢谢!

【问题讨论】:

    标签: asp.net web-applications iis-7 asp.net-authentication asp.net-authorization


    【解决方案1】:

    使用User.Identity.Name 获取用户名。

    Windows 身份验证不使用FormsAuthenticationTicket

    【讨论】:

    • User.Identity.Name 也返回相同的 domain\windowsUser 而不是 ASP.NET 用户。 User.Identity 的类型为 WIndowsIdentity,并且 AuthenticationType 设置为“Negotiate”。
    • 您在 web.config 中使用什么身份验证系统?窗体还是窗口?
    • 表格。这是一个 sn-p: 授权>
    • 你是如何对人进行身份验证的?
    • 使用我自己的代码检查密码。如果检查成功,我称之为:FormsAuthentication.RedirectFromLoginPage(userName, rememberUser.Checked);
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-25
    • 2012-10-23
    • 2017-05-16
    • 1970-01-01
    • 2017-06-28
    • 2011-06-27
    相关资源
    最近更新 更多