分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 技术分享

.NetCore -MVC 路由的配置

发布时间:2023-09-06 02:35责任编辑:赖小花关键词:配置MVC
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

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved