NARKOZ
NARKOZ

Reputation: 27901

How to redirect in ASP.NET based on URL?

How can I redirect user based on host in aspx page? For example, I want redirect user to localhost99.com if url is host22.com and redirect to host22.com if url is localhost99.com

I tried out something like this:

        protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.ServerVariables["SCRIPT_NAME"] + "?" + Request.ServerVariables["QUERY_STRING"] != "host22.com/default.aspx") 
        {
            Response.Redirect("http://localhost99.com/");
        }
    }

Please help. Thanks.

Upvotes: 0

Views: 388

Answers (1)

No Refunds No Returns
No Refunds No Returns

Reputation: 8336

You would probably have better success doing this upstream in the request handling pipeline. Check out the possibility of inserting an http handler module in your application.

Upvotes: 1

Related Questions