回发和 URL 重写器
我遇到了一个有趣的问题,我碰壁了。我的登录页面有问题,该页面实现表单身份验证并使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论