Session

core路由

电脑版发表于:2021/5/31 11:51

前言

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");
                });


关于TNBLOG
TNBLOG,技术分享。技术交流:群号677373950
ICP备案 :渝ICP备18016597号-1
App store Android
精彩评论
{{item.replyName}}
{{item.content}}
{{item.time}}
{{subpj.replyName}}
@{{subpj.beReplyName}}{{subpj.content}}
{{subpj.time}}
猜你喜欢