C# 放弃不触发或抛出错误消息
我有下面的一段代码,它抛出了一条我需要在web.config上启用会话的错误消息,但是我到目前为止没有发现任何东西,所以有人能告诉我它应该是如何工作的吗 我也尝试过将代码放在Page_Load上的Decline中,但服务器似乎避开了会话的指示:C# 放弃不触发或抛出错误消息,c#,asp.net,session,C#,Asp.net,Session,我有下面的一段代码,它抛出了一条我需要在web.config上启用会话的错误消息,但是我到目前为止没有发现任何东西,所以有人能告诉我它应该是如何工作的吗 我也尝试过将代码放在Page_Load上的Decline中,但服务器似乎避开了会话的指示: public partial class Decline : DataPage { protected Decline() { Session.RemoveAll(); Se
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");
}
}
这是完整的信息:
只有在配置文件或Page指令中将enableSessionState设置为true时,才能使用会话状态。还请确保System.Web.SessionStateModule或自定义会话状态模块包含在应用程序配置的\\
部分中
这运行的是.NET4框架,以下答案中的配置不太适合我当前的项目。因为它提供了一个.NETMVC2解决方案。因此,如果在.NET4上有一个等价物,这会很有帮助
<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>
另外,我已经为我的页面提供了以下行
<%@ Page Title="" Language="C#" CodeFile="Decline.aspx.cs" Inherits="Decline" enableSessionState="true" %>
不管它是否存在,都没有任何区别。也在IIS 7.5上运行我遇到了同样的问题,我就是这么做的
在web.Config中,只需添加以下内容
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
您可以尝试删除一个会话,并检查它是否已被这样删除
Session.Remove("test");
if (Session["test"] == null)
{
//woooo it work ;
}
else
{
// what ????
}
Session.Remove("test");
if (Session["test"] == null)
{
//woooo it work ;
}
else
{
// what ????
}