asp.net-web-api-routing

At what point in a Web API app can I intercept the URI arguments and route the calls accordingly?

时间秒杀一切 提交于 2019-12-11 02:27:28
问题 Note: This question is indeed somewhat similar to this one, but I think I can put it in a simpler and more specific way. I'm using Castle Windsor to intercept the URI passed to my Web API app to register the appropriate concrete class to the Controller's constructor. What I want to be able to do is pass a "site number" on the URI, perhaps always as either the first or last arg. IOW, for site 42, instead of http://localhost:28642/api/platypi/GetAll ...it would be: http://localhost:28642/api

How do you handle routing in ASP.Net WebApi routing with a '/' in your string parameter

走远了吗. 提交于 2019-12-11 01:55:22
问题 I have a C# WebApi 4 project where I am trying to have a string parameter with the character '/' in it. For example, I am passing a path in the parameter: http://localhost/api/MyController/mypath/testing I want the id parameter in Get method in MyController to be populated with "mypath/testing". However, it looks like the route things this should be two parameters and can't find where to go so it is returning in error. I think I need to change the default route. Currently in the WebApiConfig

API Routes: Multiple operations with path

别等时光非礼了梦想. 提交于 2019-12-10 18:37:17
问题 I am trying to configure my API routes, and I can't seem to get around this error from Swagger: 500 : {"Message":"An error has occurred.","ExceptionMessage":"Not supported by Swagger 2.0: Multiple operations with path 'api/Doors/{OrganizationSys}' and method 'GET'. I understand why I am getting the error, but I'm not sure how to fix it. Here are the API end points: public IHttpActionResult Get(int organizationSys) { .... } public IHttpActionResult Get(int organizationSys, int id) { .... }

WebApi Multiple actions were found with GetAll() and GetByIds(int[] ids)

 ̄綄美尐妖づ 提交于 2019-12-10 03:32:36
问题 Using the standard route: config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional } ); With these actions: public class ValuesController : ApiController { // GET api/values public string GetAll() { return "all"; } // GET api/values/5 public string GetById(int id) { return "single"; } // GET api/values?ids=1&ids=2 public string GetByIds([FromUri] int[] ids) { return "multiple"; } And make a request to /api/values , I

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

北战南征 提交于 2019-12-10 01:59:15
问题 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

Web API 2 Is it possible to load a route/controller programmatically?

旧时模样 提交于 2019-12-09 10:43:44
问题 I am currently working on an enterprise web application that uses WCF to implement a REST API. It utilizes a VirtualPathProvider to catch requests to *.svc files (which don't actually exist), and then builds them on the fly to dynamically load the associated WCF services. This allows the system to have "modules" that can be added to the application at runtime without impacting the web server or anyone using it. What I would like to know, is if the same is conceptually possible with Web API 2.

Modular ASP.NET Web API: how to add/remove route at run time to a Web API

谁都会走 提交于 2019-12-09 05:59:45
问题 I am trying to design a modular Web API application (It is not an MVC app!) in which a user in admin role can add or remove modules without restarting the ASP.NET application. Module: each module is an assembly (.dll file) that contains at least one class which is derived from ApiController . Routing is based on Attribute Routing in ASP.NET Web API 2 Production of modules (assemblies) is not in the scope of this question. Modules (assembly files) are copied to / deleted from `~/plugins/

Exception in HttpControllerDispatcher

谁说胖子不能爱 提交于 2019-12-08 23:04:37
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 dictionary.","ExceptionType":"System.Collections.Generic.KeyNotFoundException","StackTrace":" at System

Controller actions naming convention

点点圈 提交于 2019-12-08 17:20:49
问题 As naming convention says, WebApi controller actions name should be Get(), Put(). Post() etc. But tell me if I have a controller as CustomerController , now I want to have two actions inside of it. One is GetCustomerById(int id) and another one is GetCustomerByAge(int age) . Here both the actions accept one parameter as int. So, if I want to make the url user friendly like "api/customer/" also I want to follow the actions naming convention like only Get(int id)/Get(int age) , how will I do it

Web api interface works locally but not on Azure

落花浮王杯 提交于 2019-12-08 14:46:08
问题 My case is very similar to this question, but since he did not get an answer I thought I'd throw some more input. Everything works fine locally (on the VS embedded server). When I deploy to Azure, I get a 404 error accompanied by "No type was found that matches the controller named...". However, when I load the routedebugger module the mapping seems ok even on Azure. What can I do to debug that problem? Thanks, Alex Edit: my routes are created this way: GlobalConfiguration.Configuration