保持会话的存活C# [英] Keeping session alive C#

查看:135
本文介绍了保持会话的存活C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的HttpWebRequest登录到一个网站,并获得会话cookie。我的应用程序擦伤某些页面,并最终变为空闲,导致会议死亡。



什么是防止这种情况的好方法,并作为 - 仅仅怎么curious-做网页浏览器呢?


解决方案

浏览器本身不这样做的。他们只能这样做,如果Web应用程序本身建立在对它的支持。例如,有可能是一些JavaScript,这使得AJAX请求每隔30秒左右发送保持会话活着型向服务器发出请求,然后将去更新其状态信息,以反映最近的活动现在,从而防止会话超时。



然而,在上面的例子中,客户,即HTML / JavaScript的浏览器,而服务器会已经写在一起,因此,这种类型的内置功能。<​​/ p>

如果你是不负责的服务器端应用程序,因此不能建立不断-alive功能集成到自己动手,你最好的选择是要么亲自到该网页,翻阅所有的JavaScript,试图找到可能的保活的代码(寻找的setTimeout,setInterval的或任何相关的方法他们使用的js框架)。当然,可能没有任何这样的功能,在这种情况下,最好的办法是简单地刷新你是在页面(即发送同样的请求再次)


I'm using HttpWebRequest to log on to a website and get the session cookie. My application scrapes certain pages, and eventually becomes idle, resulting in the session dying.

What would be a good way to prevent this and -just being curious- how do web browsers do it?

解决方案

Browsers by themselves don't do this at all. They only do so if the Web App itself builds in support for it. For example there might be some javascript which makes an AJAX request every 30 seconds or so to send a "keep-session-alive" type request to the server, which would then go and update its state information to reflect that the "most recent activity" was now, and hence prevent a session timeout.

In the example above however, the "client" i.e. html/javascript in the browser, and the "server" would have been written together and thus this type of functionality built in.

If you aren't responsible for the server-side app, and thus can't build the "keep-alive" functionality into it yourself, your best bet would be to either physically go to the web-page, look through all the javascript to try to find possible "keep-alive" code (look for SetTimeout, SetInterval or related methods in any js frameworks they may be using). Of course there might not be any such functionality, in which case your best bet is to simply "refresh" the page you are on (i.e. send the same request again)

这篇关于保持会话的存活C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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