asp.net-web-api-routing

The Constraint Entry 'httpMethod' on the Route Must Have a String Value

夙愿已清 提交于 2020-01-12 23:32:53
问题 I have an asp.net Web API project, and in my WebApiConfig file, I have the following route defined: config.Routes.MapHttpRoute( name: "Web API Get", routeTemplate: "api/{controller}", defaults: new { action = "Get" }, constraints: new { httpMethod = new HttpMethodConstraint("GET") } ); For integration testing purposes, I want to make a request to an HttpSelfHostServer to verify that we are receiving the proper data back from the api call. I am making the HttpRequestMessage as follows: var

The Constraint Entry 'httpMethod' on the Route Must Have a String Value

偶尔善良 提交于 2020-01-12 23:32:45
问题 I have an asp.net Web API project, and in my WebApiConfig file, I have the following route defined: config.Routes.MapHttpRoute( name: "Web API Get", routeTemplate: "api/{controller}", defaults: new { action = "Get" }, constraints: new { httpMethod = new HttpMethodConstraint("GET") } ); For integration testing purposes, I want to make a request to an HttpSelfHostServer to verify that we are receiving the proper data back from the api call. I am making the HttpRequestMessage as follows: var

The Constraint Entry 'httpMethod' on the Route Must Have a String Value

半城伤御伤魂 提交于 2020-01-12 23:32:08
问题 I have an asp.net Web API project, and in my WebApiConfig file, I have the following route defined: config.Routes.MapHttpRoute( name: "Web API Get", routeTemplate: "api/{controller}", defaults: new { action = "Get" }, constraints: new { httpMethod = new HttpMethodConstraint("GET") } ); For integration testing purposes, I want to make a request to an HttpSelfHostServer to verify that we are receiving the proper data back from the api call. I am making the HttpRequestMessage as follows: var

No HTTP resource was found that matches the request URI error in ASP.NET Web API

↘锁芯ラ 提交于 2020-01-04 08:26:33
问题 This is a sketch of my TransferController class. All this is Web API code. public class TransferController : ApiController { [HttpGet, ActionName("Queue")] public IEnumerable<object> GetQueue(Guid sessionId) {...} [HttpDelete, ActionName("Delete")] public void Delete(Guid sessionId, Guid fileId) {...} [HttpGet, ActionName("Cancel")] public bool Cancel(Guid sessionId, Guid fileId) {...} [HttpGet, ActionName("UploadedBytes")] public long GetUploadedByteCount(Guid sessionId, Guid fileId) {...}

Exception in HttpControllerDispatcher

戏子无情 提交于 2020-01-03 02:22:54
问题 In my WebApiConfig::Register(...) I replaced the HttpControllerSelector with my own controller selector. When I fire off a POST request the SelectController member is correctly called and I return a ControllerDescriptor with the correct type of my controller. But then HttpControllerDispatcher is raising an exception saying "The given was not present in the dictionary." Anyone has an idea how to debug such error? The complete exception is message is: The given key was not present in the

ASP NET Web API Route templates

我怕爱的太早我们不能终老 提交于 2020-01-02 06:17:24
问题 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:

ASP NET Web API Route templates

亡梦爱人 提交于 2020-01-02 06:17:00
问题 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:

Routing an Angular 2 app with Web API

拜拜、爱过 提交于 2020-01-01 05:45:09
问题 I have an Angular 2 application created with Angular CLI. This has to call a .NET 4.6 Web API. The route setup of this is driving me nuts. For Angular, the default folder for output is /dist . Angular CLI does all the minification and tree-shaking you can dream of and then outputs both its JavaScript files and index.html to that folder. So if I run index.html , those files are retrieved from the same folder. Everything works well, because index.html contains a tag like this one: <base href="/

Enabling CORS with WebAPI PUT / POST requests?

南笙酒味 提交于 2019-12-28 11:48:06
问题 I've tried following this post but I'm still not quite there: CORS support for PUT and DELETE with ASP.NET Web API In my web.config I have the following: <system.webServer> <validation validateIntegratedModeConfiguration="false" /> <httpProtocol> <customHeaders> <!-- TODO: don't let anyone make requests - only approved clients --> <add name="Access-Control-Allow-Origin" value="*" /> <add name="Access-Control-Allow-Headers" value="Content-Type" /> <add name="Access-Control-Allow-Methods" value

WebAPI controller inheritance and attribute routing

浪子不回头ぞ 提交于 2019-12-28 06:45:42
问题 I have few controllers that inherit from the same base class. Among the different actions that they don't share with each other, they do have a few that are completely identical. I would like to have these on my base class because they all work completely the same it's just that they're accessed through different routes. How should I define these actions with several different routes? My inherited classes also have a RoutePrefixAttribute set on them so each of them is pointing to a different