Asp.net core 迁移学习之路由

12 篇文章 0 订阅
6 篇文章 0 订阅

路由

主要是区域路由的配置Area

原项目做法:

  1.  
    public class AppApiAreaRegistration : AreaRegistration
        {
            public override string AreaName
    
            {
                get
    
                {
                    return "AppApi";
                }
    
            }
    
    
            public override void RegisterArea(AreaRegistrationContext context)
    
            {
    
                context.MapRoute(
    
                    "AppApi_default",
    
                    "AppApi/{controller}/{action}/{id}",
    
                    new { action = "Index", id = UrlParameter.Optional }
    
                );
    
            }
    
        }
    Core中需要Startup当中的Configure里配置区域路由配置
  2. 
    app.UseRouting();
    
    app.UseEndpoints(endpoints =>
    
                    {
    
                     endpoints.MapAreaControllerRoute(
    
                     name: "WeChatWebSite_default",
    
                     areaName: "WeChatWebSite",
    
                     pattern: "WeChatWebSite/{controller}/{action}/{id}");
    
                    );})

     

接着需要在每个区域控制器上标明

 

这样每个访问都可以通过Localhost:43899/WeChatWebSite/Index找到这个区域控制器

 

原项目基本路由配置在RouteConfig.cs文件中:

public class RouteConfig

    {

        public static void RegisterRoutes(RouteCollection routes)

        {

            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");



            routes.MapRoute(

                name: "Default",

                url: "{controller}/{action}/{id}",

                defaults: new { controller = "Home", action = "Login", id = UrlParameter.Optional },

                namespaces: new string[] { "HongYang.IHis.Site.Controllers" }

            );



            // 用户app token失效回跳页面

            routes.MapRoute(

                name: "RedirectAppHome",

                url: "APPH5/Shared/RedirectHome",

                defaults: new { controller = "Home", action = "RedirectHome", id = UrlParameter.Optional },

                namespaces: new string[] { "HongYang.IHis.Site.Controllers" }

            );

        }

    }

 

2,Core中则需要在Startup当中Config里配置普通控制器路由

app.UseEndpoints(endpoints =>

                {

                 endpoints.MapControllerRoute(

                        name: "AppApi_default",

                        pattern: "AppApi/{controller}/{action}/{id}"

                     // new { action = "Index", id = UrlParameter.Optional }

                     );               

 })

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

新时代丘鸣山

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值