是什么导致“会话状态已创建一个会话ID,但无法保存,因为响应已被应用程序刷新”。 [英] What's causing “Session state has created a session id, but cannot save it because the response was already flushed by the application.”

查看:185
本文介绍了是什么导致“会话状态已创建一个会话ID,但无法保存,因为响应已被应用程序刷新”。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我断断续续得到此故障。

I'm getting this fault intermittently.

我发现这个链接,总结得相当好了我能找到的谷歌:
<一href=\"http://www.wacdesigns.com/2009/02/03/session-state-has-created-a-session-id-but-cannot-save-it-because-the-response-was-already-flushed-by-the-application/\">http://www.wacdesigns.com/2009/02/03/session-state-has-created-a-session-id-but-cannot-save-it-because-the-response-was-already-flushed-by-the-application/

I found this link which summarises fairly well what I was able to find on the Google: http://www.wacdesigns.com/2009/02/03/session-state-has-created-a-session-id-but-cannot-save-it-because-the-response-was-already-flushed-by-the-application/

基本上,它说,你可以尝试设置Web配置设置DisplayWhenNewSession,或者尝试通过获取Session.SessionID中的Session_OnStart踢会话状态的东西融入生活。

Basically it says you can try setting the web config setting DisplayWhenNewSession, or try kicking the session state thing into life by getting the Session.SessionID in the Session_OnStart.

但没有人:

A)有一个这样的解释

a) have an explanation for this

甚至更好,B)有一个久经考验的修复

or even better, b) have a tried and tested fix

我知道我不能刷新做任何事情,会影响到HTTP响应头后的反应。如果我这样做会导致错误的每次的但是这是间歇性的。该SessionID的肯定应该由ASP.NET页面响应的自动创建之初,在ASPX页面或在Page_Load(这是我的全部刷新的称呼)任何东西之前。

I realise that I can't flush the response after doing anything that would affect the http response header. If I did this it would cause an error every time but this is intermittent. The SessionID should surely be created by ASP.NET at the beginning of the page response automatically, before anything in the ASPX page or the Page_Load (which is where all my flushes are called).

更新:
经过思考我意识到这是一个流媒体文件到浏览器的时候发生。大多数浏览器实际上是搜索引擎机器人。我可以开始下载,然后关闭浏览器,因此presumably浏览器不等待下载到取消下载操作完成之前重新创建此错误。我也看到了这一点其他正常的网页,但99%的时间是下载页面。

Update: On reflection I realise this is happening when streaming a file down to the browser. Most of the browsers are actually search engine bots. I can recreate this error by starting a download and then closing the browser, so presumably the browsers are not waiting for the download to complete before cancelling the download operation. I have also seen this on other, normal pages, but 99% of the time it is download pages.

推荐答案

我有!

在Global.asax文件中你这样做:

In the global.asax file you do this :

void Session_Start(object sender, EventArgs e) 
{
    // Code that runs when a new session is started
    string sessionId = Session.SessionID;
}

那么容易。它的工作原理!

So easy. It works!

这篇关于是什么导致“会话状态已创建一个会话ID,但无法保存,因为响应已被应用程序刷新”。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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