1

I have the following piece of code that is throwing an error message that I need to enable Session on web.config, but none of the things I have found so far, so can anyone tell me how it is suppose to be working?.

I have tried also place the code within Decline on Page_Load but the server seems to avoid the Session's instructions:

    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");
       }
    }

This is the full message:

Session state can only be used when enableSessionState is set to true, either in a configuration file or in the Page directive. Please also make sure that System.Web.SessionStateModule or a custom session state module is included in the <configuration>\<system.web>\<httpModules> section in the application configuration

This is running a .net 4 framework and the configurations coming from the following answer do not quite fit my current project. Since that is providing a .net mvc 2 solution. So it would be helpful is there is an equivalent for this on .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

Also I already provided my page with the following line

<%@ Page Title="" Language="C#" CodeFile="Decline.aspx.cs" Inherits="Decline" enableSessionState="true" %> 

which does not make any difference at all if it is there or not. Also is running on IIS 7.5

Community
  • 1
  • 1

1 Answers1

0

I had the same problem and this is what i did in web.Config just add this

  <system.webServer>
     <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>

and in your page that your are using

EnableSessionState="True"

and you can try to remove one session and check if it has been remove like this

Session.Remove("test");
if (Session["test"] == null)
{
//woooo it work ;
}
else
{
// what ????
}
Reza Del
  • 763
  • 10
  • 30