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. |