1

Basically I am trying to check the Session value from the .html page. SO what far I done that is

In ASPX I am storing the value in session and redirect into an html page.

Session["user_id_no"] = "1234";
Response.Redirect(url);  

From HTML I am calling an REST GET method.

var check= $.ajax({
    url: "/loginCheck",
    type: 'GET',
    success: function (result) {
        return result;
    },
    async:false
});

REST API and Method implementation

[HttpGet]
[Route("loginCheck")]
public bool checkLoginStatus()
{
    SessionClass sc = new SessionClass();
    bool user_id_check = sc.check("user_id_no");       
    return user_id_check;
}

Session Class is implemented as

public class SessionClass : System.Web.UI.Page
{
     public bool check(string sessionName)
     {
         if (Session[sessionName] == null)
             return false;
         return true;
     }
}

But I am getting exception.

HResult=-2147467259 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 \\ section in the application configuration.

But in my web.config

<sessionState mode="InProc" timeout="30" />

I have also went through some question

  1. How to access Session variables and set them in javascript?
  2. Getting session value in javascript
  3. 'Session' does not exist in the current context
  4. Session state can only be used when enableSessionState is set to true either in a configuration
R.A.Munna
  • 1,699
  • 1
  • 15
  • 29
  • @Div from `4th no SO link` in accepted answer says to configure any one `enableSessionState="true"` or `sessionState mode="InProc" ` and I have done the secondnd one. – R.A.Munna Dec 15 '17 at 06:39

2 Answers2

0

Have you ever tried this?

using System.Web.SessionState;

public class SessionClass :  IRequiresSessionState
{
     public bool check(string sessionName)
     {
         if (HttpContext.Current.Session[sessionName] == null)
             return false;
         return true;
     }
}
Mike
  • 721
  • 7
  • 13
-1

you need to enableSessionState in your config as exception says

 <system.web>
      <pages enableSessionState="true" /> 
 </system.web>

check this answer for more information

Bassem Mamar
  • 328
  • 2
  • 14