Currently, I am attempting to verify the Session
value from the .html page
. Here is what I have done so far:
In ASPX
I am setting the value in session
and then redirecting to an html
page.
Session["user_id_no"] = "1234";
Response.Redirect(url);
Within HTML, I am initiating a REST GET
method.
var check= $.ajax({
url: "/loginCheck",
type: 'GET',
success: function (result) {
return result;
},
async:false
});
Implementation of REST API and Method
[HttpGet]
[Route("loginCheck")]
public bool checkLoginStatus()
{
SessionClass sc = new SessionClass();
bool user_id_check = sc.check("user_id_no");
return user_id_check;
}
The Session Class has been created as follows:
public class SessionClass : System.Web.UI.Page
{
public bool check(string sessionName)
{
if (Session[sessionName] == null)
return false;
return true;
}
}
Unfortunately, I am encountering an 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.
Even though my web.config
contains the following:
<sessionState mode="InProc" timeout="30" />
I have also referred to some related questions
- How to access Session variables and set them in javascript?
- Getting session value in javascript
- 'Session' does not exist in the current context
- Session state can only be used when enableSessionState is set to true either in a configuration