asp.net-web-api-routing

Web API 2 routing attributes work in one controller but not another

荒凉一梦 提交于 2019-12-06 01:35:08
Using .NET 4.5.1, Web API 2, Visual Studio 2013: I have a Web API which has the following routes... /api/providers/specialties /api/providers/specialties/123 /api/providers/specialties/medicine These work as expected... the first one gets a list of all specialties, the second one gets specialty ID 123, and the third gets all specialties with "medicine" in the name. I also have these routes... /api/locations/specialties /api/locations/specialties/123 /api/locations/specialties/ortho Only the last two work... the first one returns this error: No HTTP resource was found that matches the request

HttpRouteBuilder - Where did it go and Why?

社会主义新天地 提交于 2019-12-06 01:34:20
问题 I upgraded my nuget package for the Web API 2 from the RC1 to 5.0.0, and was dumbfounded to find that HttpRouteBuilder, which used to be accessible, was made internal. Along with that, there is no longer an overload for HttpConfiguration.MapHttpAttributeRoutes that takes HttpRouteBuilder as an argument. Why? I was using that, and it solves a major problem in my project. What do I use instead? Background: I am writing a server that uses Attribute Routing for Web API 2. I implemented a class

Elmah.axd on WebAPI 2.2 - No HTTP Resource was found

↘锁芯ラ 提交于 2019-12-05 18:26:05
I'm trying to access /elmah.axd in my broswer, but it returns: {"message":"No HTTP resource was found that matches the request URI 'http://services.domain.com/elmah.axd'."} The server is local (127.0.0.1) and even on that I have my web.config Elmah settings to secure it this way: <elmah> <security allowRemoteAccess="true" /> </elmah> My WebApiConfig looks like: public static void Register(HttpConfiguration config) { // Web API configuration and services // Locally only you will be able to see the exception errors config.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.LocalOnly; // Web API

ASP NET Web API Route templates

不羁的心 提交于 2019-12-05 14:14:52
I have an entity named Agency with following apis GET http://localhost:37331/api/agency?start=1&limit=10&status=1 GET http://localhost:37331/api/agency/2 POST http://localhost:37331/api/agency PUT http://localhost:37331/api/agency DELETE http://localhost:37331/api/agency/4 POST http://localhost:37331/api/agency/activate/3 POST http://localhost:37331/api/agency/deactivate/3 GET http://localhost:37331/api/agency/types The route templates I used are config.Routes.MapHttpRoute( name: "ControllerActionIdApi", routeTemplate: "api/{controller}/{action}/{id}", defaults: new { }, constraints: new { id

Web Api Controller in other project, route attribute not working

风流意气都作罢 提交于 2019-12-05 13:51:46
问题 I have a solution with two projects. One Web Api bootstap project and the other is a class library. The class library contains a ApiController with attribute routing. I add a reference from web api project to the class library and expect this to just work. The routing in the web api is configured: config.MapHttpAttributeRoutes(); The controller is simple and looks like: public class AlertApiController:ApiController { [Route("alert")] [HttpGet] public HttpResponseMessage GetAlert() { return

ASP.NET WebAPI Supported Media Types per Method

大城市里の小女人 提交于 2019-12-05 08:33:39
Given a method in a controller: public class CustomerController : ApiController { [HttpGet] public CustomerDto GetById([FromUri] int id) { . . return customerDto } } Is there a way to specify supported Media Types with an attribute? For instance, CustomerDto is a complex class and will only serialize with JSON (application/json) not XML (application/xml) but could also accept PDF (application/pdf). Is there something like this: [HttpGet(Accepts.JSON, Accepts.PDF)] or [HttpGet][AcceptJSON][AcceptXML] or [HttpGet][Accept("application/json")][Accept("application/pdf")] If the incoming request

ASP.NET Web Api 2 - Subdomain Attribute Routing

倾然丶 夕夏残阳落幕 提交于 2019-12-05 04:33:41
问题 I've been using AttributeRouting for quite some time in my MVC application. However, one thing it always lacked is subdomain routing in Web Api (among other features in that library that work with MVC but not Web Api). Now I just read about the new improvements in Web Api regarding Attribute Routing and that it's now included with Web Api out of the box. However, I see no mention of subdomain routing. Is it supported in Web Api 2? If not, how can I get subdomain routing in my Web Api so that

ASP.NET 5 HTML5 History

筅森魡賤 提交于 2019-12-05 04:03:01
I'm upgrading my project to ASPNET5. My application is a AngularJS Web App that uses HTML5 Url Routing ( HTML5 History API ). In my previous app I used the URL Rewrite IIS Module with code like: <system.webServer> <rewrite> <rules> <rule name="MainRule" stopProcessing="true"> <match url=".*" /> <conditions logicalGrouping="MatchAll"> <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> <add input="{REQUEST_URI}" matchType="Pattern" pattern="api/(.*)" negate="true" /> <add input="{REQUEST_URI}" matchType=

The path template on the action in controller is not a valid OData path template

六眼飞鱼酱① 提交于 2019-12-05 01:36:26
I am getting the following error: The path template 'GetClients()' on the action 'GetClients' in controller 'Clients' is not a valid OData path template. Resource not found for the segment 'GetClients'. My controller method looks like this public class ClientsController : ODataController { [HttpGet] [ODataRoute("GetClients(Id={Id})")] public IHttpActionResult GetClients([FromODataUri] int Id) { return Ok(_clientsRepository.GetClients(Id)); } } My WebAPIConfig file has builder.EntityType<ClientModel>().Collection .Function("GetClients") .Returns<IQueryable<ClientModel>>() .Parameter<int>("Id");

Web Api HTTPPost not accepting int

随声附和 提交于 2019-12-05 01:34:08
I am trying to just pass in body a int and it does not work Why do I need to create a class with a property of type int ? (then it works) WORKS [HttpPost] [Route("api/UpdateMainReversed")] public IHttpActionResult UpdateMainVerified(DataAccess.Entities.RequestMain mainValues) { ....} DO NOT WORK [HttpPost] [Route("api/UpdateMainReversed")] public IHttpActionResult UpdateMainVerified(int mainId) { ....} Testing with Postman http://localhost:13497/api/UpdateMainReversed Body { "mainId" : 1615 } 1.Your [HttpPost] expects a int but from body you are passing a json object. you should pass json