开发者

inline to handle url redirect

开发者 https://www.devze.com 2023-03-08 06:07 出处:网络
I am migrating a site from siteA.domain.com to siteB.domain.com.All the page paths remain the same.The problem is it\'s a gradual migration, and not every path is being migrated at the same time.So wh

I am migrating a site from siteA.domain.com to siteB.domain.com. All the page paths remain the same. The problem is it's a gradual migration, and not every path is being migrated at the same time. So what I need to do is check the path the user is going to, and if it's a member of a list of migrated sites, then redirect the user from siteA.开发者_如何学运维domain.com/path to siteB.domain.com/path

I was hoping to add in-line c# code to the master page. Any thoughts/examples of this?


I believe the correct way would be to add some routes to the Global.asax.

       void Application_Start(object sender, EventArgs e)
    {
        // Code that runs on application startup
        RegisterRoutes(RouteTable.Routes);
    }
            public static void RegisterRoutes(RouteCollection routes)
    {
        routes.MapPageRoute("home",
            "home",
            "~/Home.aspx");
    }

The above code will let you type "http://mysite.com/home" and it will redirect to the Home.aspx page. You could redirect to http://myothersite.com/Home.aspx instead of using the ~, or relative path.

You can add routes for each and every page that you have in some master list.


I would have a list of address in your config that have been migrated, then in the page_load of the master page check the current url (on of the properties in Request.Url I can't remember which) and see if it is the list from the config.

Simple, but quite often the simple way is the best. Plus if it is a temporary thing there is no point wasting time doing anything complex.


Any reason not to use IIS for the redirect? SO Question - How to redirect a URL path in IIS?


Create an IHttpHandler that intercepts all incoming requests and redirects appropriately.

0

精彩评论

暂无评论...
验证码 换一张
取 消