asp.net-web-api-routing

Controllers split by areas [duplicate]

我只是一个虾纸丫 提交于 2019-11-28 07:48:35
Possible Duplicate: How do I register a controller that has been created in an AREA I have the question - is it possible to do the next? I have three Areas: _Default SiteOne SiteTwo Inside each area i have a ApiController with the same name, but in different namespaces of course: MvcAppliaction.Areas._Default.Controllers.ValuesController MvcAppliaction.Areas.SiteOne.Controllers.ValuesController MvcAppliaction.Areas.SiteTwo.Controllers.ValuesController I also have a value of current (which i would like to use) Area in configuration. I would like to map user to controller in the proper Area

The inner handler has not been assigned using WebApi Delegating handler

守給你的承諾、 提交于 2019-11-28 07:29:47
问题 I have got a problem with WebApi throwing an exception here in my code: public class WebApiAuthenticationHandler : DelegatingHandler { private const string AuthToken = "AUTH-TOKEN"; protected override Task<HttpResponseMessage> SendAsync( HttpRequestMessage request, CancellationToken cancellationToken) { var requestAuthTokenList = GetRequestAuthTokens(request); if (ValidAuthorization(requestAuthTokenList)) { // EXCEPTION is occuring here!.... return base.SendAsync(request, cancellationToken);

Attribute Routing and CreatedAtRoute

邮差的信 提交于 2019-11-28 07:13:21
问题 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

Enabling CORS with WebAPI PUT / POST requests?

断了今生、忘了曾经 提交于 2019-11-28 05:59:14
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="GET, POST, PUT, DELETE, OPTIONS" /> </customHeaders> </httpProtocol> <handlers> <remove name=

Routing based on query string parameter name

有些话、适合烂在心里 提交于 2019-11-28 05:51:47
I'm trying to configure routing in my MVC4 WebAPI project. I want to be able to search for products based on their name or their type like so: /api/products?name=WidgetX - returns all products named WidgetX /api/products?type=gadget - returns all products of type gadget The routes are configured like this: config.Routes.MapHttpRoute( name: "Get by name", routeTemplate: "api/products/{name}", defaults: new { controller = "ProductSearchApi", action = "GetProductsByName", name = string.Empty } ); config.Routes.MapHttpRoute( name: "Get by type", routeTemplate: "api/products/{type}", defaults: new

WebAPI controller inheritance and attribute routing

点点圈 提交于 2019-11-28 01:03:55
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 route. Example I have base abstract class called Vehicle and then inherited Car , Bike , Bus etc. All

Route parameter with slash “/” in URL

霸气de小男生 提交于 2019-11-27 22:42:29
I know you can apply a wildcard in the route attribute to allow / such as date input for example: [Route("orders/{*orderdate}")] The problem with wildcard is only applicable to the last paramter in URI. How do I solve the issue if want to have the following URI: [Route("orders/{orderdate}/customers")] Update: I know there are few options to solve the issue by refactoring the code so please do not offer a solution something like: change the route template to [Route("orders/customers/{orderdate}")] change the date to a different format (e.g. "dd-mm-yyyy" ) ronnie @bet.. I think the

Versioning ASP.NET Web API 2 with Media Types

半世苍凉 提交于 2019-11-27 22:17:54
I'm using ASP.NET Web API 2 with attribute routing but i can't seem to get the versioning using media types application/vnd.company[.version].param[+json] to work. I get the following error: The given key was not present in the dictionary. which originates from testing the key _actionParameterNames[descriptor] in FindActionMatchRequiredRouteAndQueryParameters() method. foreach (var candidate in candidatesFound) { HttpActionDescriptor descriptor = candidate.ActionDescriptor; if (IsSubset(_actionParameterNames[descriptor], candidate.CombinedParameterNames)) { matches.Add(candidate); } } Source:

Why is my Web API method with double args not getting called?

瘦欲@ 提交于 2019-11-27 15:39:00
I have a Web API method that takes two double args: Repository interface: public interface IInventoryItemRepository { . . . IEnumerable<InventoryItem> GetDepartmentRange(double deptBegin, double deptEnd); . . . } Repository: public IEnumerable<InventoryItem> GetDepartmentRange(double deptBegin, double deptEnd) { // Break the doubles into their component parts: int deptStartWhole = (int)Math.Truncate(deptBegin); int startFraction = (int)((deptBegin - deptStartWhole) * 100); int deptEndWhole = (int)Math.Truncate(deptEnd); int endFraction = (int)((deptBegin - deptEndWhole) * 100); return

Passing multiple parameters to web API GET method

狂风中的少年 提交于 2019-11-27 08:46:22
问题 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 {