路由
主要是区域路由的配置Area
原项目做法:
-
Core中需要Startup当中的Configure里配置区域路由配置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 } ); } }
-
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 }
);
})