asp.net-web-api-routing

ASP.NET ApiController inside a webform can't reach methods

眉间皱痕 提交于 2019-12-08 13:25:34
问题 I can't reach any methods from my ApiController in anyway, the routing does appear if i try to reach it by a browser but no methods are shown. My Controller: namespace AgroRiego.Controllers { public class datacontrol : ApiController { [HttpGet, Route("api/get")] public string Get([FromUri]string user, string pass) { string check = SQL.Reader("SELECT * FROM users WHERE username='" + user + "' AND password='" + pass + "'"); if (String.IsNullOrWhiteSpace(check)) { return "error en credenciales";

Web Api Core 2 distinguishing GETs

一曲冷凌霜 提交于 2019-12-08 03:54:50
问题 Why can't Web API Core 2 tell these apart? [HttpGet] public IEnumerable<string> Get() { return new string[] { "value1", "value2" }; } // GET api/values?name=dave [HttpGet] public string Get(string name) { return $"name is {name}"; } Here's what happens - Both http://localhost:65528/api/values and http://localhost:65528/api/values?name=dave cause the first Get() method to execute. This exact code works fine in Web Api 2. I know multiple ways of getting around this, but I don't know why it

Multiple types were found that match the controller

不问归期 提交于 2019-12-07 21:24:36
问题 I'm trying to api versioning using header but in different folder structure like below. In Controller folder have V1 sub folder inside that CustomerController.cs and In Controller folder have V2 sub folder inside that CustomerController.cs when I user api version using URL above works fine. my issue is When I try this approach with header it is giving me below error: { "Message": "An error has occurred.", "ExceptionMessage": "Multiple types were found that match the controller named 'customer

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

杀马特。学长 韩版系。学妹 提交于 2019-12-07 15:42:44
问题 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

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

99封情书 提交于 2019-12-07 14:41:16
问题 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

An API version is required, but was not specified. webapi

我的未来我决定 提交于 2019-12-07 07:28:24
var constraintResolver = new DefaultInlineConstraintResolver() { ConstraintMap = { ["apiVersion"] = typeof( ApiVersionRouteConstraint ) } }; config.MapHttpAttributeRoutes(constraintResolver); config.AddApiVersioning(o => o.AssumeDefaultVersionWhenUnspecified = true); [ApiVersion("2.05")] [RoutePrefix("api/v{version:apiVersion}/ger")] public class caGerController [Route("~/api/ger/getDetail")] [Route("getDetail")] GetGerData [ApiVersion("1")] [RoutePrefix("api/v{version:apiVersion}/gerDetail")] public class caGerDetailsController caGerController [Route("~/api/gerDetail/getDetail")] [Route(

Create Web API for request with code and term query parameters

烈酒焚心 提交于 2019-12-06 12:39:15
In ASP.NET MVC4 application Json Web api needs to be created to serve requests with term and code url parameters like: http://myapp.com/api/customers returns all customers http://myapp.com/api/customers?term=partofname returns 0 .. n customers and http://myapp.com/api/customers?code=customercode returns 1 customer always code is customer id which can contain / and other characters which are not allowed in url passed to windows http server by http.sys in windows kernel API controller below is tried but it causes compile error Error Type 'Erp.Controllers.CustomersController' already defines a

Multiple types were found that match the controller

醉酒当歌 提交于 2019-12-06 09:49:17
I'm trying to api versioning using header but in different folder structure like below. In Controller folder have V1 sub folder inside that CustomerController.cs and In Controller folder have V2 sub folder inside that CustomerController.cs when I user api version using URL above works fine. my issue is When I try this approach with header it is giving me below error: { "Message": "An error has occurred.", "ExceptionMessage": "Multiple types were found that match the controller named 'customer'. This can happen if the route that services this request ('api/{controller}/{id}') found multiple

The 'DelegatingHandler' list is invalid because the property 'InnerHandler' of 'handler' is not null

一笑奈何 提交于 2019-12-06 09:07:54
问题 I have a custom message handler that I add globally as follows: public class CustomerHandler : DelegatingHandler { public CustomHandler(HttpConfiguration httpConfiguration) { InnerHandler = new HttpControllerDispatcher(httpConfiguration); } } config.MessageHandlers.Add(new CustomHandler(config)); However, I get the following error: The 'DelegatingHandler' list is invalid because the property 'InnerHandler' of 'CustomHandler' is not null. Parametername: handlers So I changed the code to:

Creating a route that can accept a DateTime in the URI with asp.net web api 2 attribute routing

时光怂恿深爱的人放手 提交于 2019-12-06 03:12:21
I'm trying to see if I need to write a custom IHttpRouteConstraint or if I can wrestle with the built-in ones to get what I want. I can't see to find any good documentation on this anywhere. Basically, here's my action: [Route("var/{varId:int:min(1)}/slot/{*slot:datetime}")] public async Task<HttpResponseMessage> Put(int varId, DateTime slot) { ... } What I want is to be able to call it like this: PUT /api/data/var/1/slot/2012/01/01/131516 and have the framework bind 19 to var id and a DateTime with a value of "Jan 1st, 2012, 1:15:16pm" as the "slot" value. Following the guide from here: http: