如何重置ASP.Net会话状态超时使用Ajax请求 [英] How to reset ASP.Net sessions state timeout with ajax request

查看:173
本文介绍了如何重置ASP.Net会话状态超时使用Ajax请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的一个ASP.Net全的Ajax网站。因为所有的操作都​​在做由Ajax请求,任何回发请求将不会发送到server.In另一方面我有一个发送一个Ajax请求,检查会话的JavaScript计时器,如果它过期重定向用户到登录页面。

问题就在这里:当用户正在使用页面上20分钟,所有的操作都​​会做20分钟后Ajax请求的会话过期,用户将重定向到登录页面(由JavaScript的定时器)正是在与网页的工作。所以,我需要刷新与Ajax请求的会话状态。但如何?我该怎么办,要由一个Ajax请求复位会话状态超时!?!!

依靠我的谷歌搜索结果中,我不能preform通过Ajax请求,因为店里的SessionID在客户端的cookie中,并对其进行更新需要preform回发请求:(

注意:会话状态设置在是InProc 与模式超时= 20

对不起我的英语不好的语法,我相信新的英文

问候,Foroughi

更新:是否一个Ajax请求更新会话状态超时!!

更新:当我的用户登录到网站我设置会话是这样的:

 会话[用户ID] = UserObject.Id;
 

和我所有的网页我用了一些网络的方法preform操作是这样的:

  [WebMethod的]
公共静态OPR1(Paramethers ...)
{

   //问题就在这里,我怎么可以更新用户ID会议prevent到期,我该怎么更新

   //执行我的codeS为preform OPR1

}
 

解决方案

如果您正在使用webMethods,你应该装点您的方法,如

  [WebMethod的(EnableSession =真)
 

另外,如果你需要保持你的会话还活着,你应该尝试创建一个实现IRequireSessionState该接口允许获取/套(反序列化/序列化)会话变量,最终将下滑会话超时一个HttpHandler。

这是对会话和Ajax调用的好文章。

<一个href="http://seejoelprogram.word$p$pss.com/2008/11/10/maintaining-aspnet-session-state-in-an-ajax-application/" rel="nofollow">http://seejoelprogram.word$p$pss.com/2008/11/10/maintaining-aspnet-session-state-in-an-ajax-application/

希望这会有所帮助。

问候。

I am working on an ASP.Net Full-Ajax site. Because all operations have doing by Ajax requests, any postback request will not send to server.In other hand I have a javascript timer that send an ajax request to check sessions and if it expired redirect user to login page.

Problem is here: When user is working on page for 20 minutes and all operations will do with ajax requests after 20 minutes its session expired and user will redirect to login page (by that javascript timer) exactly during working with page. So I need to refresh its session state with ajax request. But how ?How can I do that to reset sessions state timeout by an ajax request!?!!

Depend on my Google search results, I can not be preform by ajax request because SessionId store in client as a cookie and to update it need to preform a post back request :(

Note : Session state is set on InProc mode with timeout = 20

Sorry about my bad English syntax, I am new in English

Regards, Foroughi

UPDATE : Does an ajax request update sessions state timeout?!!

UPDATE : When my user login to site I set a session like this :

Session["UserId"] = UserObject.Id;

and in all my page I use some web method to preform operation like this :

[WebMethod]
public static Opr1 (Paramethers...)
{

   //Question is here , how can i update UserId  session to prevent to expire,how can i update it

   //execute my codes to preform Opr1

}

解决方案

If you are using WebMethods you should decorate your methods like

[WebMethod(EnableSession = true)]

Further if you need to keep your session alive you should try create an HTTPHandler that implements IRequireSessionState this interface allows to get/set(deserialize/serialize) the session variables that will eventually slide session timeout.

This is a good article about the sessions and ajax calls.

http://seejoelprogram.wordpress.com/2008/11/10/maintaining-aspnet-session-state-in-an-ajax-application/

Hope this will be helpful

Regards.

这篇关于如何重置ASP.Net会话状态超时使用Ajax请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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