I have a custom routing class which I added to the RouteConfig
public static class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.Add(new CustomRouting());
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
}
The CustomRouting class looks like this:
public class CustomRouting : RouteBase
{
public override RouteData GetRouteData(HttpContextBase httpContext)
{
var requestUrl = httpContext.Request?.Url;
if (requestUrl != null && requestUrl.LocalPath.StartsWith("/custom"))
{
if (httpContext.Request?.HttpMethod != "GET")
{
// CustomRouting should handle GET requests only
return null;
}
// Custom rules
// ...
}
return null;
}
}
Essentially I want to process requests that go to the /custom/*
path with my custom rules.
But: Requests that are not "GET", should not be processed with my custom rules. Instead, I want to remove the /custom
segment at the beginning of the path and then let MVC continue with the rest of the routing configured in RouteConfig.
How can I achieve that?