MVC 如何设定默认默认路由为指定的Area下的某个action(笔记)
感谢这篇博文的作者:http://blog.csdn.net/chenqiangdage/article/details/48136601
最近使用VS2015开发一个统一认证服务,想将API自己生成的帮助页面设置为默认页面。
示例:
namespace IOV.Authrize.Areas.HelpPage { /// <summary> /// 帮助页面路由注册 /// </summary> public class HelpPageAreaRegistration : AreaRegistration { /// <summary> /// 区域名称 /// </summary> public override string AreaName { get { return "HelpPage"; } } /// <summary> /// 注册 /// </summary> /// <param name="context"></param> public override void RegisterArea(AreaRegistrationContext context) { context.MapRoute( "HelpPage_Default", "Help/{action}/{apiId}", new { controller = "Help", action = "Index", apiId = UrlParameter.Optional }); HelpPageConfig.Register(GlobalConfiguration.Configuration); } } }
修改RouteConfig代码为:
public class RouteConfig { /// <summary> /// 注册路由 /// </summary> /// <param name="routes"></param> public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapRoute( "Default", "{controller}/{action}/{id}", new { controller = "Help", action = "Index", id = UrlParameter.Optional }, new[] { "IOV.Authrize.Areas.HelpPage.HelpController" } ).DataTokens.Add("area", "HelpPage"); } }