Lilith River
Lilith River

Reputation: 16468

Optional regex groups in an MVC route?

I'm running into a problem with an optional regex clause (\.ashx)? in an ASP.NET MVC route

routes.IgnoreRoute("resizer\\.debug(\\.ashx)?");
routes.IgnoreRoute("[^?]+\\.(psd|bmp|gif|exif|png|tif|tiff|tff|jpg|jpeg|jpe|jif|jfif|jfi)(\\.ashx)?");

I get the error

The route URL cannot start with a '/' or '~' character and it cannot contain a '?' character.
Parameter name: routeUrl

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.ArgumentException: The route URL cannot start with a '/' or '~' character and it cannot contain a '?' character.
Parameter name: routeUrl

[ArgumentException: The route URL cannot start with a '/' or '~' character and it cannot contain a '?' character.
Parameter name: routeUrl]
   System.Web.Routing.RouteParser.Parse(String routeUrl) +21953
   System.Web.Routing.Route.set_Url(String value) +12
   System.Web.Routing.Route..ctor(String url, IRouteHandler routeHandler) +9
   System.Web.Mvc.RouteCollectionExtensions.IgnoreRoute(RouteCollection routes, String url, Object constraints) +106
   System.Web.Mvc.RouteCollectionExtensions.IgnoreRoute(RouteCollection routes, String url) +6
   MvcApplication2.MvcApplication.RegisterRoutes(RouteCollection routes) in C:\Users\Administrator\Documents\resizer\Tests\Hidden\MvcApplication2\Global.asax.cs:15
   MvcApplication2.MvcApplication.Application_Start() in C:\Users\Administrator\Documents\resizer\Tests\Hidden\MvcApplication2\Global.asax.cs:29

How do you do optional regex groups in MVC routes?

Upvotes: 1

Views: 642

Answers (1)

Related Questions