处理程序与IRequiresSessionState不会扩展会话超时 [英] Handler with IRequiresSessionState does not extend session timeout

查看:267
本文介绍了处理程序与IRequiresSessionState不会扩展会话超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个处理程序,这样,使用IRequiresSessionState:

I have a handler, like this, using IRequiresSessionState:

public class MyHandler : IHttpHandler, IRequiresSessionState
{
  // code
}

在code,我能够读取和设置会话值。我还要检查确保调用者登录,这一切工作正常。

In the code, I am able to read and set Session values. I also check ensure that the caller is logged in. That all works fine.

该网站使用窗体身份验证,所以在web.config中,我有这样的:

The web site uses forms authentication, so in the web.config, I have this:

<authentication mode="Forms">
   <forms loginUrl="Login.aspx" timeout="10" slidingExpiration="true"></forms>
</authentication>

问题是,AJAX调用从客户机到服务器的code MyHandler的不延长会话生命!

因此​​,即使用户正忙自己的最后一个完整的页面加载后,发送和接收来自服务器的数据,他们超时10分钟。

So even if the user is busy sending and receiving data from the server, they time out 10 minutes after their last full page load.

在处理程序中,我专门试图改变一个值在每个呼叫会话,而且甚至没有延伸出来的时候。

In the handler, I've tried specifically changing a value is the session on each call, but not even that extends the time out.

有什么建议?

推荐答案

终于得到了解决这个......诸如此类的。

Finally got a solution to this... sort of.

我放弃了试图让处理器来完成这项工作,而是被称为一个正常的ASPX页面。在该页面中,我去掉了HTML code和使用的Response.Write(...)发回一些​​JSON的,我想。然而,即使如此,我的会话没有被延长!

I abandoned trying to get the handler to do the job, and instead called a normal ASPX page. In that page, I removed the HTML code, and used Response.Write(...) to send back some JSON that I wanted. However, even with that, my session was not being extended!

我终于意识到,在preRender事件,我用 Response.ClearHeaders()。这就是问题所在。事实证明,在Forms身份验证系统更新会话票证的cookie在需要的时候,但我的code的运行之前,将它添加到标题。所以,当我清除了头,我抹去了新的Cookie之前,它被发送给浏览器。

I finally realized that in the PreRender event, I used Response.ClearHeaders(). That was the problem. It turns out that the Forms authentication system was updating the session ticket cookie when needed, but was adding it to the Headers before my code was running. So when I cleared the headers, I was erasing the new cookie before it was sent to the browser.

所以,如果您有与会议没有被延长的问题,检查以确保您的code未使用 ClearHeaders()

So, if you are having problems with sessions not being extended, check to make sure that your code is not using ClearHeaders()!

这篇关于处理程序与IRequiresSessionState不会扩展会话超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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