【发布时间】:2015-01-24 01:37:09
【问题描述】:
我需要在现有的表单身份验证 Web 应用程序之上实现 Windows 身份验证,以获取我的应用程序中某些页面的 Windows 用户名。为此,我正在关注这篇文章 - Mixed Mode Authentication。
如本文所述,我在 IIS 中的同一网站下创建了一个具有“Windows”身份验证的附加应用程序。我在 Application_AuthenticateRequest 中将 'userName' 设置为 cookie 票证的用户数据
protected void Application_AuthenticateRequest(object sender, EventArgs e)
{
WindowsIdentity ident = WindowsIdentity.GetCurrent();
WindowsPrincipal wind_princ = new WindowsPrincipal(ident);
string theUserName = wind_princ.Identity.Name.ToString();
FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, "qaAuto_winAuth_Ticket", DateTime.Now, DateTime.Now.AddMinutes(120), false, theUserName, "/");
string encTicket = FormsAuthentication.Encrypt(ticket);
Response.Cookies.Add(new HttpCookie("myTicket", encTicket));
Response.Redirect("http://FormsAuthenticationApp/default.aspx");
}
调试时,我可以看到 cookie 票证具有正确的用户名值,例如 - myDomain/myWindowsUserName。
但是在重定向之后,在 FormsAuthenticationApp 的“Application_AuthenticateRequest”中,当我读取此 cookie 的值时,我得到的是 NT AUTHORITY\NETWORK SERVICE,而不是在 windows 身份验证 myDomain/myWindowsUserName 中设置的内容。
过去两天一直在摸索如何在 FormsAuthenticationApp 中获取用户名。任何帮助将不胜感激,
非常感谢!
【问题讨论】:
标签: asp.net authentication iis cookies