PageBase 中的会话

发布于 2024-09-13 15:36:00 字数 524 浏览 0 评论 0原文

我在我的 Web 应用程序中使用页面库,其中页面库将在每个页面加载之前被调用。

我计划通过检查会话状态中的值来检查用户是否有效。

但我收到一条错误消息说

仅当在配置文件或 Page 指令中将 enableSessionState 设置为 true 时,才能使用会话状态。另请确保 System.Web.SessionStateModule 或自定义会话状态模块包含在`

那么是否可以从页面库中读取会话值。

添加了代码

public class PageBase : System.Web.UI.Page
{
    public PageBase()
    {
        if (Session["UserID"] == null)
        {
            Response.Redirect("Home.aspx", false);       
        }
    }
}

谢谢, 杰布利

I am using a page base in my web application where the page base will be called before the page load of every page.

I plan to check if the if the user is valid by checking the value in session state.

But i am getting an error message saying

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 `

So is it possible to read the session values from the page base.

Added the code

public class PageBase : System.Web.UI.Page
{
    public PageBase()
    {
        if (Session["UserID"] == null)
        {
            Response.Redirect("Home.aspx", false);       
        }
    }
}

Thanks,
Jebli

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

因为看清所以看轻 2024-09-20 15:36:04

该错误表明您尚未在 web.config(和/或页面)中启用会话状态。

一切都应该按照您的预期进行。

您不应该从构造函数中调用代码。

从 Page_load 事件中调用它。

The error indicates that you have not enabled session state in your web.config (and/or page).

Everything should work as you expect it to do.

You should not call the code from the constructor.

Call it from the Page_load event.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文