3

我正在 C# Web 应用程序中设置混合模式身份验证。我在 WindowsAuthentication 网站中设置了 AuthCookie,然后尝试重定向到 FormsAuthentication 网站。我认为 cookie 位于正确的路径中,因为 Context.Request.IsAuthenticated 是正确的。不幸的是,我一直被重定向到 FormsAuthentication 网站的登录页面,就好像我没有设置 AuthCookie 一样。到底是怎么回事?

我不熟悉 ASP.NET 中的身份验证是如何工作的,所以请像我 5 岁一样向我解释一下。谢谢,:)

编辑:这是制作 cookie 的 WindowsAuth 站点的 Global.asax 中的事件。此站点当前位于 FormsAuth 站点“下”的路径 /authentication 中。

void Application_PostAuthenticateRequest(Object sender, EventArgs e)
{
    WindowsIdentity ident = WindowsIdentity.GetCurrent();
    WindowsPrincipal p = new WindowsPrincipal(ident);
    if (p.Identity.IsAuthenticated)
    {
        HttpCookie cookie = FormsAuthentication.GetAuthCookie(p.Identity.Name, false);
        FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(cookie.Value);
        // Store roles inside the Forms cookie.
        FormsAuthenticationTicket newTicket = new FormsAuthenticationTicket(
            ticket.Version, ticket.Name, ticket.IssueDate, ticket.Expiration,
            ticket.IsPersistent, "", ticket.CookiePath);
        string encTicket = FormsAuthentication.Encrypt(newTicket);
        Context.Response.Cookies.Add(new HttpCookie(".GWBTroubleTickets", encTicket));
    }
    Response.Redirect("/employee/home.aspx");
}
4

1 回答 1

0

每个页面可能会多次调用该事件。- https://stackoverflow.com/a/5947309/57883 你没有if/else周围的Response.Redirect("/employee/home.aspx");

尝试使用自定义属性而不是此事件

于 2012-08-07T12:23:53.313 回答