回发和URL重写器

时间:2012-01-01 08:25:33

标签: c# asp.net-membership urlrewriter

我遇到了一个有趣的问题,我碰到了一堵砖墙。我有一个登录页面的问题,它实现了表单身份验证并使用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;

}

任何想法或解决方案都将非常受欢迎。的问候,

MD

0 个答案:

没有答案