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

91

Solution 1

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.

Solution 2

I am not sure I fully understand your description of the problem, but here are a few things to consider:

You mention a send button. If this is an , clicking it fires a javascript postback to the server. This postback is to the original URL. I'm not sure what you are modifying with Javascript, but I don't think it would change the postback URL (and querystring).

If you need to perform logic to redirect you might want to execute in the button click event on the server.

If you don't need to execute any logic on the server, you could to the redirect with javascript:

window.location = "chooseRecipients.aspx";

Solution 3

Can't test this theory (running from memory at the moment), but give this a shot:

(sorry, cleaned up the code a bit as well)

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()
        }
    }
}
Share:
91
M4rk
Author by

M4rk

Updated on June 28, 2022

Comments

  • M4rk
    M4rk almost 2 years

    My understanding of ZooKeeper is that a client will always execute requests in an ordered manner from ITS point of view.

    Therefore if the client 1 issues:

    • write node A
    • 2 reads node A, B
    • write node B they will be executed in that order.

    But in case client 1 has also a watch on a node C, and client 2 writes that node, does that write on node C impacts/blocks reads from client 1?

    For example:

    • Client 1: starts watching C
    • Client 1: writes node A
    • Client 2: writes C
    • (Client 1: does client 1 block until the watch of C is fired? What if at this point the Client 1 tries to write node C?)
    • Client 1: 3 reads node A then B then C
    • Client 1: writes node B