Infinite URL Parameters for ASP.NET MVC Route
Like this: routes.MapRoute(“Name”, “tag/{*tags}”, new { controller = …, action = … }); ActionResult MyAction(string tags) { foreach(string tag in tags.Split(“https://stackoverflow.com/”)) { … } }
Like this: routes.MapRoute(“Name”, “tag/{*tags}”, new { controller = …, action = … }); ActionResult MyAction(string tags) { foreach(string tag in tags.Split(“https://stackoverflow.com/”)) { … } }
ASP.net core 3 Why this problem occurs: As part of addressing dotnet/aspnetcore#4849, ASP.NET Core MVC trims the suffix Async from action names by default. Starting with ASP.NET Core 3.0, this change affects both routing and link generation. See more: ASP.NET Core 3.0-3.1 | Breaking Changes | Async suffix trimmed from controller action names As @Chris … Read more
I hate answering my own question, but @Matt Bodily put me on the right track. The @Html.Action method actually invokes a controller and renders the view, so that wouldn’t work to create a snippet of HTML in my case, as this was causing a recursive function call resulting in a StackOverflowException. The @Url.Action(action, controller, { … Read more
You are probably combining convention based routing with attribute routing, and you should register your areas after you map the attribute routes. The line AreaRegistration.RegisterAllAreas(); should be called AFTER this line: routes.MapMvcAttributeRoutes(); The explanation (from https://devblogs.microsoft.com/aspnet/attribute-routing-in-asp-net-mvc-5/): If you are using both Areas with route attributes, and areas with convention based routes (set by an AreaRegistration … Read more
And if you want to access this from within the child action itself (rather than the view) you can use ControllerContext.ParentActionViewContext.RouteData.Values[“action”]
In my case, the controller was defined as: public class DocumentAPI : ApiController { } Changing it to the following worked! public class DocumentAPIController : ApiController { } The class name has to end with Controller! Edit: As @Corey Alix has suggested, please make sure that the controller has a public access modifier; non-public controllers … Read more
Would adding a trailing slash work for your scenario? http://localhost:33021/api/employees/employee@company.com/
If it’s only your last parameter, you could do: routes.MapRoute( “Default”, // Route name “{controller}/{action}/{*id}”, // URL with parameters new { controller = “Home”, action = “Index”, id = “” }); // Parameter defaults
What you need to do is set a token to your area name: for instance: context.MapRoute( “SomeArea_default”, “SomeArea/{controller}/{action}/{id}”, new { controller = “SomeController”, action = “Index”, id = UrlParameter.Optional } ).DataTokens.Add(“area”, “YOURAREANAME”);
There are several issues with this approach, but it boils down to being a workflow issue. You have a CultureController whose only purpose is to redirect the user to another page on the site. Keep in mind RedirectToAction will send an HTTP 302 response to the user’s browser, which will tell it to lookup the … Read more