2

我正在尝试在使用 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 的步骤进行操作,并使用以下代码段检索身份验证票:

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

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

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

4

1 回答 1

2

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

Windows 身份验证不使用FormsAuthenticationTicket.

于 2013-05-09T18:44:04.890 回答