路径的设置和过期在asp.net会话cookie

编程入门 行业动态 更新时间:2024-10-28 21:16:01
本文介绍了路径的设置和过期在asp会话cookie的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

什么我都试过没有工作。 Currenly我有以下code键更改asp会话cookie过期日期和路径,但ASP不想要听我的。我在发送的Set-Cookie头相同的cookie有时两次,有时它会发送它的默认Cookie路径无视和到期日期,有时它发出的一切如预期,有时它不会发送的Set-Cookie的。我该怎么办。这驱使我坚果:(

我的code在Global.asax中

保护无效Application_ preRequestHandlerExecute(对象发件人,EventArgs的发送){  ///只适用于会话cookie持久性要求会话信息的请求  如果(Context.Handler是IRequiresSessionState || Context.Handler是IReadOnlySessionState)  {    VAR的sessionState = ConfigurationManager.GetSection(System.Web程序/的sessionState)作为SessionStateSection;    VAR cookieName = =的sessionState空&放大器;!&安培; !string.IsNullOrEmpty(sessionState.CookieName)      ? sessionState.CookieName      ASP.NET_SessionId    VAR超时=的sessionState!= NULL      ? sessionState.Timeout      :TimeSpan.FromMinutes(20);    ///确保ASP.NET会话cookie整个子域访问。    如果(Request.Cookies时[cookieName] = NULL&放大器;!&安培;!会话= NULL&放大器;&安培;!Session.SessionID = NULL)    {      Response.Cookies [cookieName] .value的= Session.SessionID;      Response.Cookies [cookieName]。路径= Request.ApplicationPath;      Response.Cookies [cookieName] .Expires = DateTime.Now.Add(超时);    }  }}

解决方案

也许如果您尝试使用系统调用,而不是直接改变饼干..

HttpContext.Current.Session.Timeout = 20;

更新

您的意见后,从你对我说的,是你尝试使用相同的cookie,2不同的应用程序,并设置不同的超时。但是,asp可以只保留一个会话cookie的每一个。为了解决这个,你必须使用2个不同的命名饼干,而不是不同的Cookie路径。

在每个应用程序的目录,在web.config文件中,将

<的sessionState cookieName =AppSessionCookieName..>

有关更多相关信息搜索参考 msdn.microsoft/en-us/library/h6bb9cz9.aspx

希望这会解决这个问题。

Anything I have tried didn't work. Currenly I have following code to change asp session cookie expiration date and path, but asp doesn't want to listen to me. I sends same cookie in Set-Cookie header two times sometimes, sometimes it sends it's default cookie ignoring path and expiration date, sometimes it sends everything as expected, and sometimes it doesn't send Set-Cookie at all. What should I do. This drives me nuts :(

My code in Global.asax

protected void Application_PreRequestHandlerExecute(Object sender, EventArgs e) { /// only apply session cookie persistence to requests requiring session information if (Context.Handler is IRequiresSessionState || Context.Handler is IReadOnlySessionState) { var sessionState = ConfigurationManager.GetSection("system.web/sessionState") as SessionStateSection; var cookieName = sessionState != null && !string.IsNullOrEmpty(sessionState.CookieName) ? sessionState.CookieName : "ASP.NET_SessionId"; var timeout = sessionState != null ? sessionState.Timeout : TimeSpan.FromMinutes(20); /// Ensure ASP.NET Session Cookies are accessible throughout the subdomains. if (Request.Cookies[cookieName] != null && Session != null && Session.SessionID != null) { Response.Cookies[cookieName].Value = Session.SessionID; Response.Cookies[cookieName].Path = Request.ApplicationPath; Response.Cookies[cookieName].Expires = DateTime.Now.Add(timeout); } } }

解决方案

Maybe if you try using the system call, and not direct change the cookies..

HttpContext.Current.Session.Timeout = 20;

update

After your comments, and from what you say to me, is that you try to use the same cookie, for 2 different applications, and set different time outs. But asp can keep only one session for every cookie. To solve that you must use 2 different named cookies, and not different cookie path.

On each application directory, on web.config, change the

<sessionState cookieName="AppSessionCookieName" ..>

Reference for more infos msdn.microsoft/en-us/library/h6bb9cz9.aspx

Hope this solve the problem.

更多推荐

路径的设置和过期在asp.net会话cookie

本文发布于:2023-11-09 22:32:52,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1573609.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:路径   asp   cookie   net

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!