我有一个有趣的问题,我碰到了一堵砖墙。我对实现表单身份验证并使用 Intellegencia.Rewriter 的登录页面有疑问。身份验证在所有浏览器的本地主机上都可以正常工作,但在服务器上,页面的回发性质似乎在 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;
}
任何想法或解决方案将不胜感激。问候,
医学博士