asp.net-web-api-routing

Attribute Routing and CreatedAtRoute

陌路散爱 提交于 2019-11-29 13:19:48
I am trying to convert my Web Api project to use attribute routing. One thing I am not understanding is the CreatedAtRoute method for a POST request. In my WebApiConfig.cs I used to have a config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/account/{accountId}/site/{siteId}/visitor/{visitorId}/session/{sessionId}/{controller}/{action}", defaults: new { action = RouteParameter.Optional } ); I commented this out thinking it was no longer needed, but CreatedAtRoute wants the name of the route and cant find it. So how is that handled with attribute routing? Ok...this was easy once

Custom httphandler and routehandler with ASPNET MVC 4 and webapi

白昼怎懂夜的黑 提交于 2019-11-29 13:02:00
问题 I'm working on an ASPNET MVC 4 and WebApi. The webapi methods will be consumed by mobile devices. We need to secure the services and what we are using is to encrypt the data in some particular way. Now, I need to decrypt the call before the controller is reached. If the information decrypted is valid, it should continue to the controller as usual if not, I'll route the user to some error method. To accomplish this I think the best bet would be custom HttpHandler and custom RouteHandler. I'm

Query parameter route constraints

瘦欲@ 提交于 2019-11-29 07:49:06
I just started using ASP.NET Web API 2.1 and have encountered a limitation. Using Attribute Routing, I can do the following: [Route("item/{id:int}")] public IHttpActionResult GetItem(int id) { ... } The URL /item/5 will be routed to this action, but the URL /item/abc will not, because of the int constraint in {id:int} . I tried changing my URL so that the id parameter was in the query string along with its constraint, despite the use of route constraints on query parameters never being mentioned or demonstrated in the documentation. [Route("item?{id:int}")] public IHttpActionResult GetItem(int

Not supported by Swagger 2.0: Multiple operations with path

此生再无相见时 提交于 2019-11-29 05:17:22
问题 I have integrated swagger in WebApi 2 application. It works fine when application has single controller. When I added second controller in the application. I got following error : An error has occurred.","ExceptionMessage":"Not supported by Swagger 2.0: Multiple operations with path 'api/Credential' and method 'GET'. See the config setting - \"ResolveConflictingActions\" for a potential workaround","ExceptionType":"System.NotSupportedException","StackTrace":" at Swashbuckle.Swagger

Swashbuckle set manualy operationId

谁都会走 提交于 2019-11-29 03:57:12
I need to know if it's possible to set up custom operationid, or a naming convention, I mean I know that operation filter can be overwritten the way how operationId is generated https://azure.microsoft.com/en-us/documentation/articles/app-service-api-dotnet-swashbuckle-customize/ using Swashbuckle.Swagger; using System.Web.Http.Description; namespace Something { public class MultipleOperationsWithSameVerbFilter : IOperationFilter { public void Apply( Operation operation, SchemaRegistry schemaRegistry, ApiDescription apiDescription) { if (operation.parameters != null) { operation.operationId +=

Attribute routing with optional parameters in ASP.NET Web API

无人久伴 提交于 2019-11-29 00:55:48
I'm trying to use Web API 2 attribute routing to set up a custom API. I've got my route working such that my function gets called, but for some reason I need to pass in my first parameter for everything to work properly. The following are the URLs I want to support: http://mysite/api/servicename/parameter1 http://mysite/api/servicename/parameter1?parameter2=value2 http://mysite/api/servicename/parameter1?parameter2=value2&parameter3=value3 http://mysite/api/servicename/parameter1?parameter2=value2&parameter3=value3&p4=v4 The last 3 URLs work but the first one says "No action was found on the

Ambiguous Controller Names with Routing attributes: controllers with same name and different namespace for versioning

孤者浪人 提交于 2019-11-28 23:22:55
I am trying to add API versioning and my plan is to create a controller for each version in different namespace. My project structure looks like this (note: no separate area for each version) Controllers | |---Version0 | | | |----- ProjectController.cs | |----- HomeController.cs | |---Version1 | |----- ProjectController.cs |----- HomeController.cs I am using RoutingAttribute for the routes. So, ProjectController in Version0 has function with route as namespace MyProject.Controllers.Version0 { class ProjectController : BaseController { ... [Route(api/users/project/getProjects/{projectId})]

WebApi: mapping parameter to header value

ぃ、小莉子 提交于 2019-11-28 19:18:52
问题 I've done a few searches but haven't seem to find anything... Using WebApi, I would like to map an input parameter to a header value: e.g. E.g. in controller: public User GetUser(int id){ ... return user; } I want WebApi to map the id parameter to a header value (e.g. X-Auth: 1234)... rather than an URL parameter. Is this supported? 回答1: I don't think this is supported out of the box, like for example with the [FromBody] attribute. It seems you should be able to achieve this functionality by

Passing multiple parameters to web API GET method

柔情痞子 提交于 2019-11-28 14:37:06
I have created a WEB API using MySQL Database. The API works as expected for now. I sent a meter serial number and a date time parameter and then GET the expected result. Below is my controller public MDCEntities medEntitites = new MDCEntities(); public HttpResponseMessage GetByMsn(string msn, DateTime dt) { try { var before = dt.AddMinutes(-5); var after = dt.AddMinutes(5); var result = medEntitites.tj_xhqd .Where(m => m.zdjh == msn && m.sjsj >= before && m.sjsj <= after).Select(m => new { MSN = m.zdjh, DateTime = m.sjsj, Signal_Strength = m.xhqd }).Distinct(); return Request.CreateResponse

How can I tell the Web API / Castle Windsor routing engine to use a different database instance in my Repository?

别说谁变了你拦得住时间么 提交于 2019-11-28 11:35:22
问题 My understanding of the flow of events with an ASP.NET Web API Castle Windsorized app that uses Models, Repositories, and Controllers: 0) The client calls a REST method via a URI such as: http://localhost:28642/api/platypi/Count 1) Castle Windsor's routing engine maps intercepts that incoming call, sending the registered concrete class that implements the interface platypiController has as an arg in its constructor. 2) That constructor determines which of its methods is to be called (what