How can I execute Response.Redirect () from MasterPage?

I have a problem: when I call Response.Redirect () from MasterPage, it does not work. Well, debugging, I see that until the Pre_Render () target is loaded and then the previous page is displayed.

Here is the best code to explain:

(from MasterPageMain.master.cs)

protected void Page_Init(object sender, EventArgs e)
{
    string m_QueryStringValue = Request.QueryString.Get("action");
    if ((!string.IsNullOrEmpty(m_QueryStringValue)) && (m_QueryStringValue.ToLower() == "send"))
    {
        if (Session["to"] != null && Session["to"] is List<string>) this.SendPageByMail();
        else
        {
            Session.Add("AddressToSend", Request.RawUrl);
            Response.Redirect("~/chooseRecipients.aspx");
        }
    }
}

I have javascript that adds querystring by adding "action = send" when I click the submit button.

If I am on the page "~ / somethingInterestingToSend ()" - for example, I want to get to the recipient selection page, but when I click the "Send" button, I always see the same page.

What mistake?

+5
source share
4

, , , :

. , javascript . URL-. , Javascript, , URL ( ).

, .

- , javascript:

window.location = "chooseRecipients.aspx";
+1

( ), :

(, )

protected void Page_Init(object sender, EventArgs e)
{
    string m_QueryStringValue = Request.QueryString.Get("action") ?? "";
    if (m_QueryStringValue.ToLower() == "send")
    {
        if ( (Session["to"] as List<string>) != null) 
        {
            this.SendPageByMail();
        }
        else
        {
            Session.Add("AddressToSend", Request.RawUrl);
            Response.Redirect("~/chooseRecipients.aspx", false);
            HttpContext.Current.ApplicationInstance.CompleteRequest()
        }
    }
}
+1

, Request.RawUrl() :

string strURL=Request.RawUrl.ToUpper();

if (!strURL.Contains("LOGIN.ASPX") && !strURL.Contains("LOGOUT.ASPX")
    && !strURL.Contains("ERROR.ASPX") && !strURL.Contains("UNDERCONSTRUCTION.ASPX"))
{
    Response.Redirect("~/Login.aspx", false);
}

.

+1

I don’t know if its the root of your problem, but I would change 2 things. I would change your code to:

Response.Redirect("~/chooseRecipients.aspx", false);

and move the logic to PageLoad

0
source

All Articles