在我的Web应用程序中,我收到错误。 "会话状态已创建会话ID。但它无法保存,因为它已被应用程序"。
刷新我用Google搜索了这个问题,发现我必须在Global.asax Session_Start事件中存储会话ID。
string id = Session.SessionID;
但它已经存在于我的应用程序中。我不确定还有什么导致问题。我也没有使用Response.Flush()。
任何人都可以解释这个问题&解决它。
答案 0 :(得分:1)
发生这种情况是因为有时(取决于web.config配置)当Session_Start事件在全局asax中执行时,未在cookie中设置SessionID。
您遇到此错误,因为在pagelifecycle中的某个点,会话中设置了一个变量。请求结束后,ASP.NET也尝试设置SessionID,但如果请求被推迟(例如,这可以通过Response.Write或AJAX本身刷新响应),则会抛出此异常。
一个简单的修复方法是(在global.asax文件中):
void Session_Start(object sender, EventArgs e)
{
// Code that runs when a new session is started
//Ensure SessionID in order to prevent the folloing exception
//when the Application Pool Recycles
//[HttpException]: Session state has created a session id, but cannot
// save it because the response was already flushed by
string sessionId = Session.SessionID;
}