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

Web API routing with multiple parameters

I have seen the WebApiConfig get “out of control” with hundreds of routes placed in it. Instead I personally prefer Attribute Routing You are making it confusing with POST and GET [HttpPost] public List<MyRows> GetAllRows(string userName, string tableName) { … } HttpPost AND GetAllRows ? Why not instead do this: [Route(“GetAllRows/{user}/{table}”)] public List<MyRows> GetAllRows(string userName, … Read more

Not supported by Swagger 2.0: Multiple operations with path

In the file AppStart/SwaggerConfig.cs First one, you must import Linq using System.Linq; And add in the same file, this line c.ResolveConflictingActions(apiDescriptions => apiDescriptions.First()); just inside of: GlobalConfiguration.Configuration .EnableSwagger(c => { … One consideration: In your controllers, you must use the Http methods : [HttpGet] [Route(“something”)] public List<model> something(){….} [HttpGet] [Route(“something2”)] public List<model2> something2(){….} [HttpPost] [Route(“mypost1”)] … Read more

Web API routing constraint Patch missing in HttpMethod

EDIT: Update to the latest version of WebAPI currently 5.2.7 (https://www.nuget.org/packages/Microsoft.AspNet.WebApi/) ORIGINAL: If you cannot use instead: new HttpMethod(“PATCH”) See the following example use in Web API source code https://github.com/aspnetwebstack/aspnetwebstack/blob/master/src/System.Web.Http/HttpPatchAttribute.cs

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

No type was found that matches the controller named ‘User’

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

Routing with multiple Get methods in ASP.NET Web API

From here Routing in Asp.net Mvc 4 and Web Api Darin Dimitrov has posted a very good answer which is working for me. It says… You could have a couple of routes: public static class WebApiConfig { public static void Register(HttpConfiguration config) { config.Routes.MapHttpRoute( name: “ApiById”, routeTemplate: “api/{controller}/{id}”, defaults: new { id = RouteParameter.Optional }, … Read more