gpt4 book ai didi

javascript - 如何从 "Session"中的.html页面检查 `.NET`

转载 作者:行者123 更新时间:2023-11-28 10:43:36 25 4
gpt4 key购买 nike

基本上,我正在尝试检查 .html 页面 中的 Session 值。那么我到目前为止所做的是

在 ASPX 中我将值存储在 session 中并重定向到 html 页面。

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

从 HTML 我正在调用 REST GET 方法。

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

REST API 和方法实现

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

session 类实现为

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

但我遇到了异常(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.

但是在我的web.config

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

我也遇到了一些问题

  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

最佳答案

你尝试过这个吗?

using System.Web.SessionState;

public class SessionClass : IRequiresSessionState
{
public bool check(string sessionName)
{
if (HttpContext.Current.Session[sessionName] == null)
return false;
return true;
}
}

关于javascript - 如何从 "Session"中的.html页面检查 `.NET`,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47826896/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com