What am I doing wrong here? I have this route in a site that uses an older attribute routing library:
[GET(@"B{alias:regex(^[0-9A-Za-z\-_]+$)}", ControllerPrecedence = -1)]
I'm trying to upgrade the site to ASP.NET 5. This was my first attempt at doing so:
[Route(@"B{alias:regex(^[0-9A-Za-z\-_]+$)}", Order = 99)]
public virtual ActionResult ShortUrl(string alias)
{
Except it crashes with an error:
For action: 'Daniel15.Web.Controllers.BlogController.ShortUrl'
Error: While processing template 'B{alias:regex(^[0-9A-Za-z\-_]+$)}', a replacement value for the token '0-9A-Za-z\-_' could not be found. Available tokens: 'action, controller'.
Stack:
Microsoft.AspNet.Mvc.ControllerActionDescriptorBuilder.Build(ApplicationModel application)
Microsoft.AspNet.Mvc.Core.ControllerActionDescriptorProvider.GetDescriptors()
Microsoft.AspNet.Mvc.Core.ControllerActionDescriptorProvider.OnProvidersExecuting(ActionDescriptorProviderContext context)
Microsoft.AspNet.Mvc.Core.DefaultActionDescriptorsCollectionProvider.GetCollection()
Microsoft.AspNet.Mvc.Core.DefaultActionDescriptorsCollectionProvider.get_ActionDescriptors()
Microsoft.AspNet.Mvc.Routing.AttributeRoute.GetInnerRoute()
Microsoft.AspNet.Mvc.Routing.AttributeRoute.RouteAsync(RouteContext context)
Microsoft.AspNet.Routing.RouteCollection.<RouteAsync>d__9.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
System.Runtime.CompilerServices.TaskAwaiter.GetResult()
Microsoft.AspNet.Builder.RouterMiddleware.<Invoke>d__4.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
System.Runtime.CompilerServices.TaskAwaiter.GetResult()
Microsoft.AspNet.Diagnostics.ErrorPageMiddleware.<Invoke>d__5.MoveNext()
Solved - The [ and ] need to be escaped as [[ and ]].
Thanks solved it!
Most helpful comment
Solved - The
[and]need to be escaped as[[and]].