Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i have Response.Redirect() work from MasterPage?

I have a problem: when i call a Response.Redirect() from the MasterPage it doesn't work. Well, debugging i can see that until the Pre_Render() method the target page is loaded, but then is rendered the previous page.

Here's some code to better 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 a javascript that adds the querystring adding "action=send" when i click on the Send button.

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

What coul be the mistake?

like image 583
p4bl0 Avatar asked Jan 21 '09 11:01

p4bl0


1 Answers

If you want to redirect not logged in users to a login-page you should check the Request.RawUrl() like this:

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);
}

All other sites will be redirected.

like image 176
MasterPitch Avatar answered Oct 25 '22 16:10

MasterPitch