开发者

Session in PageBase

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 开发者_如何学Cin 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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜