asp.net webapi 2 attribute routing not working

Based on your information, it looks like you are not calling the httpConfig.MapHttpAttributeRoutes() (Make sure to call this before any traditional routing registrations) Since you haven’t called MapHttpAttributeRoutes, your request seems to be matching a traditional route, for example, like api/{controller}. This will not work because routes matching traditional routes will never see controllers/actions decorated … Read more

Multiple Routes on a Controller

public static class WebApiConfig { public static void Register(HttpConfiguration config) { // Web API configuration and services // Configure Web API to use only bearer token authentication. config.SuppressDefaultHostAuthentication(); config.Filters.Add(new HostAuthenticationFilter(OAuthDefaults.AuthenticationType)); // Web API routes config.MapHttpAttributeRoutes(); config.Routes.MapHttpRoute( name: “route1”, routeTemplate: “calculate”, defaults: new { controller = “Calculator”, action = “Get” }); config.Routes.MapHttpRoute( name: “route2”, routeTemplate: “v2/calculate”, … 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

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

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

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)