The original ASP. net mvc project is only a domain name site point pointing, now because the project is large, need to be split into three independent domain names site pointing to different home pages, but the program is a set of programs, the problem came out, why does the Home Page point. the routing rule in asax finds that different default homepage can be set based on different domain names accessed during initialization, and then each domain name creates a default page and redirects it to its own homepage, then, set up three sites in IIS to set the Default pages as their respective redirect pages. the aspx page is displayed. The problem is solved.
In fact, in many cases, the problem does not have to be solved so gorgeous and practical!
The Global. asax code is as follows:
String HostName = HttpContext. current. request. url. host. toString (). toLower (); // obtain the URL host address if (HostName. indexOf ("mikel")> = 0) {routes. mapRoute ("Default", // Route name "{controller}/{action}/{id}", // URL with parameters new {controller = "Home ", action = "Index", id = ""} // Parameter defaults);} if (HostName. indexOf ("kiwing")> = 0) {routes. mapRoute ("Default", // Route name "{controller}/{action}/{id}", // URL with parameters new {controller = "User ", action = "Index", id = ""} // Parameter defaults );}
Default. aspx. cs Page code:
public void Page_Load(object sender, System.EventArgs e){Response.Redirect("~/Home/Index/");}
KiwingIndex. aspx. cs Page code:
public void Page_Load(object sender, System.EventArgs e){Response.Redirect("~/User/Index/");}