System.Web.HttpException (0x80004005): Session state can only be used when enableSessionState is set to true

0

I have been trying all the suggested solution but still not working. Im using an async function and need to save a string inside a session. First problem is that when I run the code, the session give me an error :

"System.Web.HttpException (0x80004005): 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 \\ section in the application configuration.\r\n at System.Web.UI.Page.get_Session() "

Second problem is my Response.Redirect is not working.It didnt go to the page. Below is my code :

protected async Task ReceiveData()
{

 string userid = clsFuncs.GetJsonNode(DataReceive, "userid");
 string nickname = clsFuncs.GetJsonNode(DataReceive, "username");

 try
  {
   Session["userid"] = userid;
  }
 catch(Exception ex)
  {
  string ex1 = ex.ToString();
  }

 Session["nickname"] = nickname;

 Server.ClearError();
 Response.Redirect("chat.aspx", false);
}

at my indexpage.aspx:

<%@ Page Async="true" EnableSessionState="True" %>

and also in web.config:

 <system.web>
     <compilation debug="true" targetFramework="4.6.1"/>
     <httpRuntime targetFramework="4.5"/>
     <pages enableSessionState="true" />
     <sessionState mode="InProc" />
  </system.web>
  <system.webServer>
     <modules>
        <!-- UrlRewriter code here -->
        <remove name="Session" />
        <add name="Session"
           type="System.Web.SessionState.SessionStateModule" 
           preCondition="" />
     </modules>
  </system.webServer>
c#
asp.net
asked on Stack Overflow Oct 15, 2018 by raehee

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0