开发者

Response is not available in this context during page unload

开发者 https://www.devze.com 2023-02-09 05:44 出处:网络
When my asp.net aspx page unloads i am trying to check if the current session is expired.I have this code in the Page_unlaod and i get a \"Response is not available in this context\" error.What is the

When my asp.net aspx page unloads i am trying to check if the current session is expired. I have this code in the Page_unlaod and i get a "Response is not available in this context" error. What is the problem placing this code in the Page_unlaod?

protected void Page_Unload(object sender, EventArgs e)
    {
        if (Session["LoggedInUser"] == null)
        {
            Response.Redirect(Request.ApplicationPath.TrimEnd('/') + "/Login.aspx?r=" + Request.Url.ToString(), true);
        }
    }

the page is in a frame with 3 other pages so when the page is doing a postback, there is client side code that will the page 2 in the frameset to 100% visible, then when page is laoded and the document is ready it sets itself 100% visible in the frame.

I have tried placing the code in page_load but when the session has timedout the开发者_开发问答 pageload is never executed again. I have tried to place the code in the pageload of page 2 in the frameset but that causes some funny behavior and unwanted redirects.


There is only a limited amount of features available during the Unload process, and was meant for more of a cleanup process rather than a business function like this. Response is one of those features that isn't going to work here.

0

精彩评论

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