排名
6
文章
6
粉丝
16
评论
8
{{item.articleTitle}}
{{item.blogName}} : {{item.content}}
ICP备案 :渝ICP备18016597号-1
网站信息:2018-2025TNBLOG.NET
技术交流:群号656732739
联系我们:contact@tnblog.net
公网安备:
50010702506256


欢迎加群交流技术

前言
name:路由名称
pattern:模式
constraints: 约束
配置路由
//默认路由地址 app.UseEndpoints(endpoints => { endpoints.MapControllerRoute( name: "default", pattern: "{controller=Home}/{action=Index}"); });
路由传递参数, 参数名? 来表示是传递的参数而不是路由模板
app.UseEndpoints(endpoints => { endpoints.MapControllerRoute( name: "default", pattern: "{controller=Home}/{action=Index}/{id?}"); });
地址栏
路由约束(使用正则表达式)
app.UseEndpoints(endpoints => { endpoints.MapControllerRoute( name: "test", pattern: "test/{san}", constraints: new { san = "^\\d{3}-\\d{2}-\\d{4}$" ,}, defaults: new { controller = "Home", action = "Index" }); });
地址栏
修改路由端口号
启动文件中打开
public static IHostBuilder CreateHostBuilder(string[] args) => Host.CreateDefaultBuilder(args) .ConfigureWebHostDefaults(webBuilder => { //修改启动窗口 webBuilder.UseStartup<Startup>(); webBuilder.UseKestrel(); //可同时定义多个 webBuilder.UseUrls("http://*:40425","https://*:51052"); });
评价