C# 回发和URL重写器
我遇到了一个有趣的问题,我碰到了一堵砖墙。我对实现表单身份验证并使用Intellegencia.Rewriter的登录页面有问题。身份验证在所有浏览器的localhost上都可以正常工作,但在服务器上,页面的回发特性似乎在IE9中丢失,但在Chrome中却可以正常工作。我在登录页面上的代码是:C# 回发和URL重写器,c#,asp.net-membership,urlrewriter,C#,Asp.net Membership,Urlrewriter,我遇到了一个有趣的问题,我碰到了一堵砖墙。我对实现表单身份验证并使用Intellegencia.Rewriter的登录页面有问题。身份验证在所有浏览器的localhost上都可以正常工作,但在服务器上,页面的回发特性似乎在IE9中丢失,但在Chrome中却可以正常工作。我在登录页面上的代码是: bool isAuthenticated = Membership.ValidateUser(username, password); string returnUrl = Server.
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;
}
其中,AuthenticateServalid函数为:
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;
}
任何想法或解决方案都将不胜感激。问候,
医学博士