FormAuthentication在生产服务器上的IE中不起作用 [英] FormAuthentication is not working in IE on production server

查看:71
本文介绍了FormAuthentication在生产服务器上的IE中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好b $ b

表单身份验证在生产服务器上的IE中正常运行。它在本地机器上工作正常。



我通过IP地址访问生产服务器。



这是我的代码

Hi
Forms authentication is working in IE on production server. Its working fine in local machine.

I am accessing production server by IP address.

Here is my code

HttpResponse pageResponse = HttpContext.Current.Response;


Guid sessionToken = System.Guid.NewGuid();


HttpCookie authenticationCookie =
    pageResponse.Cookies[FormsAuthentication.FormsCookieName];
FormsAuthenticationTicket authenticationTicket =
    FormsAuthentication.Decrypt(authenticationCookie.Value);

authenticationCookie.Expires.AddMinutes(15);

FormsAuthenticationTicket newAuthenticationTicket =
    new FormsAuthenticationTicket(
    1,
    authenticationTicket.Name,
    authenticationTicket.IssueDate,
    authenticationTicket.Expiration,
    authenticationTicket.IsPersistent,
    sessionToken.ToString(),
    FormsAuthentication.FormsCookieName);


pageResponse.Cookies.Remove(FormsAuthentication.FormsCookieName);



HttpCookie newAuthenticationCookie = new HttpCookie(
    FormsAuthentication.FormsCookieName,
    FormsAuthentication.Encrypt(newAuthenticationTicket));

newAuthenticationCookie.HttpOnly = authenticationCookie.HttpOnly;
newAuthenticationCookie.Path = authenticationCookie.Path;
newAuthenticationCookie.Secure = authenticationCookie.Secure;
newAuthenticationCookie.Domain = authenticationCookie.Domain;
newAuthenticationCookie.Expires = DateTime.Now.AddMinutes(15);

pageResponse.Cookies.Add(newAuthenticationCookie);

推荐答案

这本来是评论,但我觉得它已经很久了。如果这没有多大帮助,请告诉我,我会尝试提供更多信息。



您能否从代码中解释您想要完成的工作以上?我问的原因是因为看起来你只想延长cookie的过期时间。删除cookie功能不会删除cookie,因为它在您的计算机上。它会更新cookie中的信息。您的方法的另一个复杂因素是cookie名称在新旧两个中都是相同的。我相信它应该显示为.ASPXAUTH。使用当前的方法,最终可能会有两个身份验证cookie。然后无法保证使用哪一个。
This was originally a comment, but I felt it was getting to long. If this doesn't help much, please let me know and I will try to provide additional information.

Could you please explain what you are trying to accomplish from the code above? The reason I ask is because it looks like you just want to extend the expiration of the cookie. The remove cookie function isn't removing the cookie since its on your machine. It updates the information in the cookie. Another complication with your method is the fact that the cookie name is the same in both the new and the old. I believe it should show as .ASPXAUTH. Using your current method you could be ending up with two authentication cookies. Then there is no guarantee of which one is being used.


这篇关于FormAuthentication在生产服务器上的IE中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆