开发者

Stop page life cycle execution after response.redirect

开发者 https://www.devze.com 2023-02-13 01:08 出处:网络
I am having a base class which implements some basic authentication for all the pages in the application.

I am having a base class which implements some basic authentication for all the pages in the application.

public class BasePage : Page
{

    public void Page_PreLoad(object sender, EventA开发者_开发技巧rgs e)
    {
        if (!IsUserValid())
        {
            Response.Redirect("default.aspx");
        }
    }


}

public class AuthenticatedUser : BasePage
{
    public void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Databind();
        }
    }
}

How to stop page life cycle for AuthenticatedUser, if the user is invalid?

Thanks, Ashwani


Response.Redirect will absolutely stop the page lifecycle execution. If you did NOT want it to stop, you would add a parameter value of false after the redirect target.

Maybe I'm not clear on what you're asking, if you wanted to stop without a redirect then use Response.End().


in Response.Redirect you can set a boolean:

Response.Redirect("Default.aspx", false);

Using method in this mode, the page lifecyce is stopped when method is called.(false is endResponse boolean)

0

精彩评论

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