回发和 URL 重写器

发布于 2024-12-23 13:14:03 字数 1920 浏览 3 评论 0原文

我遇到了一个有趣的问题,我碰壁了。我的登录页面有问题,该页面实现表单身份验证并使用 Intellegencia.Rewriter。对于所有浏览器,身份验证在 localhost 上工作正常,但在服务器上,页面的回发性质在 IE9 中丢失,但在 Chrome 中工作正常。我在登录页面上的代码是:

bool isAuthenticated = Membership.ValidateUser(username, password);
        string returnUrl = Server.HtmlDecode(Request["ReturnUrl"]);
        lblLoggedIn.Text = Page.IsPostBack.ToString();
        if (isAuthenticated && 
                            Thread.CurrentPrincipal.Identity.Name == "")
            {
                HttpContext.Current.User = AuthenticateUserIfValid(username);
                Thread.CurrentPrincipal = HttpContext.Current.User;
            }

函数 AuthenticateUserIfValid 的位置是:

public Principal.GenericPrincipal AuthenticateUserIfValid(string username)
{
    MembershipUser mpc = Membership.FindUsersByName(username)[username];
    string[] roles = Roles.GetRolesForUser(mpc.UserName);
    string strRoles = "";

    foreach (string role in roles) 
                   strRoles += strRoles != "" ? "," + role : role;

    FormsAuthenticationTicket fat = 
                    new FormsAuthenticationTicket(1, mpc.UserName.ToString(),
                 DateTime.Now, 
                           DateTime.Now.AddMinutes(30), 
                           true, 
                           strRoles, 
                           FormsAuthentication.FormsCookiePath);

    Response.Cookies.Add(
                        new HttpCookie(FormsAuthentication.FormsCookieName,
                   FormsAuthentication.Encrypt(fat)));

    Response.Cookies.Add(new HttpCookie("UserRoles", strRoles));

    Principal.GenericPrincipal myPrincipal;
    Principal.GenericIdentity myIdentity = 
                     new Principal.GenericIdentity(mpc.UserName);
    myPrincipal = new Principal.GenericPrincipal(myIdentity, roles);
    return myPrincipal;

}

任何想法或解决方案将不胜感激。问候,

医学博士

I have an interesting problem where I have hit a brick wall. I have an issue with a login page which implements forms authentication and uses Intellegencia.Rewriter. The authentication works fine on localhost for all browsers, but on the server it appears that the postback nature of the page is lost in IE9, yet works fine in Chrome. The code I have on the Login page is:

bool isAuthenticated = Membership.ValidateUser(username, password);
        string returnUrl = Server.HtmlDecode(Request["ReturnUrl"]);
        lblLoggedIn.Text = Page.IsPostBack.ToString();
        if (isAuthenticated && 
                            Thread.CurrentPrincipal.Identity.Name == "")
            {
                HttpContext.Current.User = AuthenticateUserIfValid(username);
                Thread.CurrentPrincipal = HttpContext.Current.User;
            }

Where the Function AuthenticateUserIfValid is:

public Principal.GenericPrincipal AuthenticateUserIfValid(string username)
{
    MembershipUser mpc = Membership.FindUsersByName(username)[username];
    string[] roles = Roles.GetRolesForUser(mpc.UserName);
    string strRoles = "";

    foreach (string role in roles) 
                   strRoles += strRoles != "" ? "," + role : role;

    FormsAuthenticationTicket fat = 
                    new FormsAuthenticationTicket(1, mpc.UserName.ToString(),
                 DateTime.Now, 
                           DateTime.Now.AddMinutes(30), 
                           true, 
                           strRoles, 
                           FormsAuthentication.FormsCookiePath);

    Response.Cookies.Add(
                        new HttpCookie(FormsAuthentication.FormsCookieName,
                   FormsAuthentication.Encrypt(fat)));

    Response.Cookies.Add(new HttpCookie("UserRoles", strRoles));

    Principal.GenericPrincipal myPrincipal;
    Principal.GenericIdentity myIdentity = 
                     new Principal.GenericIdentity(mpc.UserName);
    myPrincipal = new Principal.GenericPrincipal(myIdentity, roles);
    return myPrincipal;

}

Any thoughts or solutions would be most appreciated. Regards,

MD

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文