简体   繁体   中英

how to programmatically decide which content page to load , on master page load

I have a master page and two content pages with the same ContentPlaceHolderID. Is there a way to specify which content page should be loaded from the Page_Load event of the master page?

If I watch the value of:

Request.CurrentExecutionFilePath;

I see the path of the first content page.

According to the condition specified below i want to change it to the path of the second content page.

I am looking for a way to load a specific page depending on a check I do on the Master Page_Load .

If I attempt to redirect to the page from there I get stuck in an endless loop because the master page loads again before the content page and re-does the check and redirects again and again.

// in master page 
protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        if (Request.Cookies["user"] != null)
        {
            HttpCookie cookie = Request.Cookies["user"];
            string name = cookie.Value;
            Response.Redirect("~/hello_page.aspx?UserName=" + name);
        }
    }
}

Thanks in advance.

You could check on page load for the querystring you're including in the redirect. If the querystring is there, then you will have already redirected, so you can skip over the cookie-check-and-redirect block.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM