MVC routing + port modification

1. Modify the port

Url port configuration:
1) Configure port 7077 Web site: Select the project - "Right -" Properties - "Select web-" Modify fill out the "Project URL" -> click Create Virtual Directory
 2) .IIS increase a Web site port 7088, sln file and points to the current project folder statistics

2. Route:

*** Application_Start method starts when the site starts, and loaded only once, for something to do some initialization data
1). In the Application_Start method to complete the route registration, URL rules is to write to RouteCollection
after 2) The request came , it will go through the regular match, Action method to find the corresponding controller, and then call the method

 

1. In the Application_Start registered routing, Application_Start method only applied again when the service starts

2. Modify the routing configuration file

RouteConfig class public
{
public static void the RegisterRoutes (the RouteCollection routes)
{
// Ignore route, for compatibility of the previous IIS6 MVC compatible
routes.IgnoreRoute ( "{resource} .axd / {* pathInfo}");

// add custom routing
routes.Add ( "BrowserRoute", new new BrowserRoute ());
// static routing
routes.MapRoute (
name: "the About", // as long as the name is not repeated, it will not cover the
url: "About" // static routing, route matches directly write dead, the controller directly to the default action method
defaults: controller = {new new "Home", action = "the About", ID = UrlParameter.Optional}
);

Modifying the routing controller called //
// regular URL matching {controller} replaced by Test, no variable represents the controller directly to the fixed controller, i.e. a controller in the default route
all requests over so // of Test / {action} / {id } in fact actually points Home / {Action} / {ID}
routes.MapRoute (
name: "the Test",
URL: "Test / {action} / {id } ",
Defaults: Controller = {new new "Home", Action = "Index", ID = UrlParameter.Optional}
);

//正则表达式路由
//http://localhost:7088/home/test_2019_01_01
routes.MapRoute(
name: "Regex",
url: "{controller}/{action}_{year}_{month}_{day}",
defaults: new { controller = "Home", action = " about", id = UrlParameter.Optional },
constraints:new { year=@"^\d{4}", month= @"^\d{2}", day= @"^\d{2}" } //constraints表示对变量的约束
);

// default route, also known as the default routing
// HTTP: // localhost: 7088 / Home / the Test & year = 2019 & month The Day = 1 = 1?
Routes.MapRoute (
name: "the Default",
url: "{the Controller} / {Action} / {id} ", // url regular rule: after removal of the domain name matches the start port
defaults: new {controller =" Home ", action =" Index ", id = UrlParameter.Optional} // default
);
}
}

 

Guess you like

Origin www.cnblogs.com/fblogs/p/12292109.html