[Original] ASP. net mvc multi-domain name multi-site resolution

Source: Internet
Author: User

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/");}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.