【问题标题】:Session state can only be used when enableSessionState is set to true, either in a configuration file or in the Page directive.会话状态只能在 enableSessionState 设置为 true 时使用,无论是在配置文件中还是在 Page 指令中。
【发布时间】:2013-12-14 03:52:47
【问题描述】:

我遇到错误

只有在 enableSessionState 设置为 true 时才能使用会话状态,无论是在配置文件中还是在 Page 指令中。还请确保 System.Web.SessionStateModule 或自定义会话状态模块包含在应用程序配置的 \\ 部分中。

在我的 web.config 和页面中,我设置了 enableSessionState="true"

public class PageBase : System.Web.UI.Page
{
    public PageBase()
    {
        if ((string.IsNullOrEmpty(Session["ProgramID"].ToString())) && 
            (string.IsNullOrEmpty(Session["UserID"].ToString())) && 
            (string.IsNullOrEmpty(Session["CompanyID"].ToString())) && 
            (string.IsNullOrEmpty(Session["LanguageID"].ToString())))
        {
            Response.Redirect("SessionExpire.aspx", false);
        }
    }
}

我在一个继承自 Web.Ui.Page 的类中编写了这个。

你能帮我解决这个问题吗?

我错过了什么。

请帮忙

谢谢

【问题讨论】:

    标签: c# asp.net session


    【解决方案1】:

    Session 在您的Page构建期间(尚)不可用,请尝试以下操作:

    protected override void OnInit(EventArgs e)
    {
        if ((string.IsNullOrEmpty(Session["ProgramID"].ToString())) && 
            (string.IsNullOrEmpty(Session["UserID"].ToString())) && 
            (string.IsNullOrEmpty(Session["CompanyID"].ToString())) && 
            (string.IsNullOrEmpty(Session["LanguageID"].ToString())))
        {
            Response.Redirect("SessionExpire.aspx", false);
        }
    
        base.OnInit(e);
    }
    

    【讨论】:

      【解决方案2】:

      在我的情况下,只需使用 HttpContext.Current.Response 就可以解决问题

      【讨论】:

        猜你喜欢
        • 2021-05-13
        • 2012-10-27
        • 2012-12-29
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-11-02
        相关资源
        最近更新 更多