asp.net mvc dynamic level Two domain name and DNS Universal resolution configuration

Source: Internet
Author: User

Implementation of dynamic level two domain name:

Application Scenario: The current product to implement the SaaS function, because the work needs to achieve level two domain name: www. {companyurl}.xxx.com

Suppose the product main domain name entry is: www.xxx.com

When a company tenant is logged in: www.a.xxx.com

When company B tenant is logged in: www.b.xxx.com

The first thought is the rewriting of URLs: (online about the implementation of Urlrewrite.) This is also a common technique in asp.net. )

Route introduction: ASP.net routing can not be mapped to a URL for a site-specific file. Because the URL does not have to be mapped to a file, you can use a URL that describes user actions so that they are easier to understand by users. The. NET Framework 3.5 SP1 already contains asp.net Routing engine. Now that Microsoft has added better support for the routing engine in ASP.net WebForms 4.0, it uses the Expression Builder for bidirectional routing.
Typical URL patterns in an MVC application--from MSDN

The URL pattern used for routing in an MVC application typically includes the {controller} and {action} placeholders.

When a request is received, it is routed to the UrlRoutingModule object and then routed to the Mvchandler HTTP handler. The Mvchandler HTTP handler determines the controller to be invoked by adding the suffix "Controller" to the controller value in the URL to determine the type name of the controller that will handle the request. The action value in the URL determines the action method to invoke.

The code that adds routes to the MVC project, global.asax the file default MVC route.

Default configuration:

public static void RegisterRoutes (RouteCollection routes)
{
    routes. Ignoreroute ("{resource}.axd/{*pathinfo}");
    
    Routes. Maproute (
        "Default",//Route name
        "{controller}/{action}/{id}",//URL with parameters
        New {controller = "H ome ", action =" Index ", id = urlparameter.optional}//Parameter defaults
    );
    
}
protected void Application_Start ()
{
    arearegistration.registerallareas ();
    
    Registerglobalfilters (globalfilters.filters);
    RegisterRoutes (routetable.routes);
}

Involving class reference

Class Description
Route Represents a route in a Web form or MVC application.
RouteBase Serves as the base class for all classes that represent asp.net routes.
RouteTable Stores the route of an application.
Routedata The value that contains the requested route.
RequestContext Contains information about the HTTP request that corresponds to the route.
RouteValueDictionary Provides methods for storing routing Constraints, Defaults, and Datatokens objects.
Virtualpathdata Provides methods for generating URLs from routing information.

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.