=============================
General Routing
=============================
Step 1
=============================
Health.Web\App_Start\RouteConfig.cs
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
//routes.MapMvcAttributeRoutes();
//ASP.NET Web API Route Config
routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
}
Step 2
=============================
Use attribute [Route(“CustomRouteName”)]
=============================
Area Routing
=============================
Step 1:
=============================
{AreaName}AreaRegistration.cs file:
public override void RegisterArea(AreaRegistrationContext context)
{
context.Routes.MapMvcAttributeRoutes();
context.MapRoute(
"Policies_default",
"Policies/{controller}/{action}/{id}",
new { action = "Index", id = UrlParameter.Optional }
);
}
Step 2:
=============================
Health.Web\Areas\Policies\Controllers\EndorsementsController.cs
[AbpMvcAuthorize(PermissionNames.Endorsements)]
[RouteArea("Policies")]
public class EndorsementsController : HealthControllerBase { }
Step 3
=============================
[Route("~/Policies/Endorsements/{endorsementType}/{policyNo:int}")]
public async Task<ActionResult> GetPolicy(string endorsementType, long policyNo) { }
@model InsuranceCompanyInfoViewModel
@{
var areaName = ViewContext.RouteData.DataTokens["area"];
var controllerName = ViewContext.RouteData.Values["controller"].ToString();
var actionName = ViewContext.RouteData.GetRequiredString("action");
/* Acquire param data and action proccess type (update/create) */
string templateId = null;
/* grabs the parameter value from url */
string process = "create";
if (ViewContext.RouteData.Values["templateId"] != null)
{
process = "update";
templateId = ViewContext.RouteData.Values["templateId"].ToString();
}
}
// if the file is located in an Area,
// additional configurations need to be made:
// {AreaName}AreaRegistration.cs file:
public override void RegisterArea(AreaRegistrationContext context)
{
context.Routes.MapMvcAttributeRoutes();
context.MapRoute(
"Policies_default",
"Policies/{controller}/{action}/{id}",
new { action = "Index", id = UrlParameter.Optional }
);
}
// General configurations
//Health.Web\App_Start\RouteConfig.cs
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
//routes.MapMvcAttributeRoutes();
//ASP.NET Web API Route Config
routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
}
namespace Health.Web.Areas.Parameter.Controllers
{
[RouteArea("Parameter")]
[AbpMvcAuthorize(PermissionNames.ParameterMessagingTemplate)]
public class MessagingTemplateController : HealthControllerBase
{
[Route("~/Parameter/MessagingTemplate/CreateUpdate/{templateId:int?}")]
public async Task<ActionResult> CreateUpdate(int? templateId) {
var messagingTemplate =
await _messagingManager.GetFirstOrDefaultTemplateById((int)templateId);
}
[Route("~/Products/Product/PlanList/{productId?}/{planId:int?}/{popAction?}")]
[Route("~/Products/Product/PlanList/{productId?}/{popAction?}")]
public async Task<ActionResult> PlanList(string productId = null, int planId = 0, string popAction = null)
{
if (
productId != null &&
(
planId == 0 && popAction == null ||
popAction == "Create" ||
popAction == "Update" && planId > 0
)
)
}
}
}