-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathGlobalWebApiRoutesConfig.cs
79 lines (68 loc) · 3.41 KB
/
GlobalWebApiRoutesConfig.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
using System.Web.Http;
namespace MultiTenancyFramework.WebAPI
{
public class GlobalWebApiRoutesConfig
{
/// <summary>
/// Routes are mapped such that urls generated are lowercase
/// </summary>
/// <param name="routes"></param>
public static void RegisterRoutes(HttpRouteCollection routes)
{
//NB: ic === "institution code"; ver === "version"
string instCode = "Core";
routes.IgnoreRoute(routeName: "resources", routeTemplate: "{resource}.axd/{*pathInfo}");
routes.IgnoreRoute("static", "{ *staticfile}", new { staticfile = @".*\.(css|less|sass|js|gif|png|jpg|jpeg|ico|svg|ttf|eot|woff|woff2|xml|csv|txt|map|json|pdf|doc|docx|xls|xlsx|dll|exe|pdb)(/.*)?" });
// From most specific to most general
routes.MapHttpRoute( //LowerCase(
name: "Api_Default",
routeTemplate: "api/",
defaults: new { ver = "1.0", ic = instCode, area = "", controller = "Home", action = "Index", id = RouteParameter.Optional },
constraints: new { id = @"\d*" }
);
routes.MapHttpRoute( //LowerCase(
name: "Api_DefaultApi",
routeTemplate: "api/{ver}/",
defaults: new { ic = instCode, area = "", controller = "Home", action = "Index", id = RouteParameter.Optional },
constraints: new { id = @"\d*" }
);
routes.MapHttpRoute( //LowerCase(
name: "Api_Error",
routeTemplate: "api/{ver}/Error",
defaults: new { ic = instCode, area = "", controller = "Error", action = "Index", id = RouteParameter.Optional },
constraints: new { id = @"\d*" }
);
routes.MapHttpRoute( //LowerCase(
name: "Api_TenantError",
routeTemplate: "api/{ver}/{ic}/Error",
defaults: new { area = "", controller = "Error", action = "Index", id = RouteParameter.Optional },
constraints: new { id = @"\d*" }
);
routes.MapHttpRoute( //LowerCase(
name: "Api_IcOnly",
routeTemplate: "api/{ver}/{ic}",
defaults: new { area = "", controller = "Home", action = "Index", id = RouteParameter.Optional },
constraints: new { id = @"\d*" }
);
// Ambigous; this clashes with the below a lot of times
//routes.MapHttpRoute( //LowerCase(
// name: "Api_ControllerAndActionOnly",
// routeTemplate: "api/{ver}/{controller}/{action}/{id}",
// defaults: new { ic = instCode, area = "", id = RouteParameter.Optional },
// constraints: new { id = @"\d*" }
//);
routes.MapHttpRoute( //LowerCase(
name: "Api_MultiTenant",
routeTemplate: "api/{ver}/{ic}/{controller}/{action}/{id}",
defaults: new { area = "", id = RouteParameter.Optional },
constraints: new { id = @"\d*" }
);
routes.MapHttpRoute( //LowerCase(
name: "Api_MultiTenantWithArea",
routeTemplate: "api/{ver}/{ic}/{area}/{controller}/{action}/{id}",
defaults: new { id = RouteParameter.Optional },
constraints: new { id = @"\d*" }
);
}
}
}