简体   繁体   中英

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.

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.

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