using System;using System.Collections.Generic;using System.Linq;using System.Threading.Tasks;using Microsoft.AspNetCore.Builder;using Microsoft.AspNetCore.Hosting;using Microsoft.AspNetCore.Http;using Microsoft.Extensions.DependencyInjection;//参数验证,路由的参数验证配置using Microsoft.AspNetCore.Routing; ????using Microsoft.AspNetCore.Routing.Constraints;namespace Han.oi.Web{ ???public class Startup ???{ ???????// This method gets called by the runtime. Use this method to add services to the container. ???????// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 ???????public void ConfigureServices(IServiceCollection services) ???????{ ???????????//引入MVC模块 ???????????services.AddMvc(); ???????} ???????// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. ???????public void Configure(IApplicationBuilder app, IHostingEnvironment env) ???????{ ???????????if (env.IsDevelopment()) ???????????{ ???????????????app.UseDeveloperExceptionPage(); ???????????} ???????????app.UseMvc(routes => ???????????{ ???????????????routes.MapRoute( ???????????????????name: "Default", ???????????????????template: "{controller}/{action}", ???????????????????defaults: new { controller = "Home", action = "index" } ???????????????); ???????????????routes.MapRoute( ???????????????????name: "Han1", ???????????????????template: "{controller}/{action}", ???????????????????defaults: new { controller = "Han1", action = "Time"} ???????????????); ??????????????/* ?routes.MapRoute( ??????????????????name: "Tutorial", ??????????????????template: "{controller}/{action}/{name}/{age?}", ??????????????????defaults: new { controller = "Tutorial"} ???????????????); */ ??????????????/* ?routes.MapRoute( ???????????????????name: "Tutorial", ???????????????????template: "{controller}/{action}/{age}/{name}", ???????????????????defaults: new { controller = "Tutorial",action="Welcome",name = "韩"}, ???????????????????constraints: new { name = new MaxLengthRouteConstraint(5) } ???????????????); */ ???????????????routes.MapRoute( ??????????????????name: "Tutorial_1", ??????????????????template: "{controller}/{action}/{age:range(1,150)}/{name:maxlength(5)}", ??????????????????defaults: new { controller = "Tutorial", action = "Welcome", name = "韩" } ???????????????); ???????????????/* routes.MapRoute( ??????????????????name: "Tutorial_1", ??????????????????template: "hello/{action}/{age:range(1,150)}/{name:maxlength(5)}", ??????????????????defaults: new { controller = "Tutorial", action = "Welcome", name = "韩" } ???????????????); */ ???????????????routes.MapRoute( ??????????????????name: "jiaocheng_1", ??????????????????template: "jioachen/{action}.html" ???????????????); ???????????}); ???????} ???}}
.NetCore -MVC 路由的配置
原文地址:https://www.cnblogs.com/han-guang-xue/p/10559265.html