RoutePrefix vs Route

Route prefixes are associated with routes by design in attribute routing. It is used to set a common prefix for an entire controller. If you read the release notes that introduced the feature you may get a better understanding of the subject. ASP.NET Web API 2 Attribute routing ASP.NET Web API now supports attribute routing, … Read more

MVC Attribute Routing Not Working

Not only do you have to have the call to routes.MapMvcAttributeRoutes() in your App_Start\RouteConfig.cs file, it must appear before defining your default route! I add it before that and after ignoring {resource}.axd{*pathInfo}. Just found that out trying to get attribute routing to work correctly with my MVC 5 website. public static void RegisterRoutes(RouteCollection routes) { … Read more

Route parameter with slash “/” in URL

@bet.. I think the genericUriParserOptions is no longer applicable to .net 4.5 or later.. Also as suggested by @JotaBe, you might need to correctly decode the url request. In most case the %2F will be automatically translated to a slash “https://stackoverflow.com/”. So if you need to escape it you will need to decode the ‘%’ … Read more

Query string not working while using attribute routing

I was facing the same issue of ‘How to include search parameters as a query string?’, while I was trying to build a web api for my current project. After googling, the following is working fine for me: Api controller action: [HttpGet, Route(“search/{categoryid=categoryid}/{ordercode=ordercode}”)] public Task<IHttpActionResult> GetProducts(string categoryId, string orderCode) { } The url I tried … Read more