我有以下一段代码,它引发了一条错误消息,我需要在web.config上启用会话,但目前为止我没有发现任何事情,所以任何人都可以告诉我它是如何工作的?Session.Abandon未触发或投掷错误消息
我已经试过也对的Page_Load衰落中的代码,但服务器似乎避免了会话的指示:
public partial class Decline : DataPage
{
protected Decline() {
Session.RemoveAll();
Session.Clear();
Session.Abandon();
Response.Cookies.Remove("Accessed");
}
protected void Page_Load(object sender, EventArgs e)
{
Response.Redirect("~/Account/Login.aspx");
}
}
这是一个完整的消息:只能用
会话状态当enableSessionState设置为true时,无论是在配置文件中还是在Page指令中。同时请确保System.Web.SessionStateModule或$自定义会话状态模块包含在应用程序配置中的
<configuration>\<system.web>\<httpModules>
部分
这是运行.NET框架4,并从以下答案传来的配置不非常适合我目前的项目。因为这是提供.net mvc 2解决方案。因此,这将是有帮助的是有这个等同于.NET 4
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<remove name="Session" />
<add name="Session" type="System.Web.SessionState.SessionStateModule, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</modules>
</system.webServer>
Session state can only be used when enableSessionState is set to true either in a configuration
此外,我已经提供了我的网页下面的行
<%@ Page Title="" Language="C#" CodeFile="Decline.aspx.cs" Inherits="Decline" enableSessionState="true" %>
不作任何如果它存在或不存在,那么它们之间就会有所不同也就是在IIS 7.5