使用ASP.NET窗体身份验证应用程序的当前用户

使用ASP.NET窗体身份验证应用程序的当前用户,asp.net,web-applications,iis-7,asp.net-authentication,asp.net-authorization,Asp.net,Web Applications,Iis 7,Asp.net Authentication,Asp.net Authorization,我正在尝试检索使用ASP.NET窗体身份验证的web应用程序中的当前用户。 但是,System.Security.Principal.WindowsIdentity.GetCurrent().Name返回的是domain\windowsUser,而不是FormsAuthentication.RedirectFromLoginPage方法中使用的用户名。 我正在配置文件中使用窗体身份验证: <authentication mode="Forms"> <forms lo

我正在尝试检索使用ASP.NET窗体身份验证的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>
但是,ident始终为null,因为它是WindowsIdentity而不是FormsIdentity。这里怎么了?
谢谢大家!

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


Windows身份验证不使用
表单身份验证票证

User.Identity.Name还返回相同的域\windowsUser而不是ASP.NET用户。User.Identity的类型为WIndowsIdentity,AuthenticationType设置为“协商”。您在web.config中使用的身份验证系统是什么?窗体还是窗口?窗体。这里有一个片段:你们是如何验证人们的身份的?使用我自己的代码来检查密码。如果检查成功,我将其称为:FormsAuthentication.RedirectFromLoginPage(用户名,rememberUser.Checked);
    if (Request.IsAuthenticated)
    {
         var ident = User.Identity as FormsIdentity;
        if (ident != null)
        {

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