asp.net-web-api-routing

Controllers split by areas [duplicate]

雨燕双飞 提交于 2019-12-17 18:33:37
问题 This question already has answers here : Closed 7 years ago . 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

Versioning ASP.NET Web API 2 with Media Types

雨燕双飞 提交于 2019-12-17 16:18:13
问题 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(

Multiple HttpPost method in Web API controller

冷暖自知 提交于 2019-12-16 23:43:08
问题 I am starting to use MVC4 Web API project, I have controller with multiple HttpPost methods. The Controller looks like the following: Controller public class VTRoutingController : ApiController { [HttpPost] public MyResult Route(MyRequestTemplate routingRequestTemplate) { return null; } [HttpPost] public MyResult TSPRoute(MyRequestTemplate routingRequestTemplate) { return null; } } Here MyRequestTemplate represents the template class responsible for handling the Json coming through the

WebApi 2 Building nested route using attribute routing. Results in mapping to two controllers at the same time

心已入冬 提交于 2019-12-13 15:42:31
问题 I have two controllers one named "Products" and the other "ProductsGroup" [RoutePrefix("api/{clientUrl}/products")] public class ProductsController : BaseApiController { /// <summary> /// Get all products from a client /// </summary> /// <returns></returns> [Route("")] public HttpResponseMessage Get() { var model = Repository.GetProducts(ClientId).Select(p => ModelFactory.Create<ProductsModel>(p)); return Request.CreateResponse(HttpStatusCode.OK, model); } } [RoutePrefix("api/{clientUrl}

Asp.Net MVC4 + Web API Controller Delete request >> 404 error

只愿长相守 提交于 2019-12-13 12:25:44
问题 I have a VS2012 MVC4 solution where I test Web API Controllers. I successfully tested the GET, POST, PUT but the DELETE still got me an http 404 error. When I set a breakpoint in my 'DeleteMovie' action in my api controller, the breakpoint is never reached. I read a lot of posts about this problem but no one helped me. Here is my API Controller for the DELETE: [HttpDelete] public HttpResponseMessage DeleteMovie(int id) { // Delete the movie from the database // Return status code return new

Correct web-api controller action method definition for jsonp request

五迷三道 提交于 2019-12-13 06:14:03
问题 I have a simple web api controller action method: public class WeightController : ApiController { [HttpGet] [AcceptVerbs("GET")] public int GetWeight(int weightId) { return 5; } } I use default route config for webapi public static void Register(HttpConfiguration config) { config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional } ); } I need to do cross domain call so I use jsonp call: $.ajax({ url: 'api/Weight/1',

Webapi Routing with Integer array and Actions

為{幸葍}努か 提交于 2019-12-13 04:56:31
问题 This issue is driving me nuts. I have a get method that takes ID array with custom ModelBinder (I can call http://xckvjl.com/api/results/1,23,34,) I want to introduce Gets on actions. (so that I can call as http://alskjdfasl.com/api/results/latest) I have the following web api routing. config.Routes.MapHttpRoute("DefaultApi", "{controller}/{id}", new { id = RouteParameter.Optional }); config.Routes.MapHttpRoute("ApiWithAction", "{controller}/{action}"); I have tried with (Please note here

Updating Navigation Property in oData WebAPI

匆匆过客 提交于 2019-12-13 04:31:41
问题 I am using WebAPI oData. The requirement is to update the Navigation property of the entity. public class Question { public int QuestionId { get; set; } public string QuestionTitle { get; set; } public string QuestionBody { get; set; } public List<Response> Responses { get; set; } //navigation property } public class Response { public string ResponseId { get; set; } public int QuestionId { get; set; } //fk public string ResponseBody { get; set; } } Now if I use the following link to fetch the

Routing error: No HTTP resource was found that matches the request URI

柔情痞子 提交于 2019-12-13 03:24:33
问题 I'm trying to make the API call http://localhost:56578/v1/reports to call my GetReports() method. However I continue to get the error message in the subject. I'm following the ms docs here via the route prefix: https://docs.microsoft.com/en-us/aspnet/web-api/overview/web-api-routing-and-actions/attribute-routing-in-web-api-2#route-prefixes What am I doing wrong? ReportV1Controller.cs [Authorize] [RoutePrefix("v1/reports")] .... .... [Route("")] public IHttpActionResult GetReports()

WebApiConfig.Register Clears routes defined by RouteConfig.RegisterRoutes apon deployment

淺唱寂寞╮ 提交于 2019-12-13 00:43:13
问题 I'm on struggle street here, When I try to add API controllers it seems to destroy all my MVC base routes and area routes. On my application start I call protected void Application_Start() { AreaRegistration.RegisterAllAreas(); WebApiConfig.Register(GlobalConfiguration.Configuration); //FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); Util.RazorDebuggingSetup(); BundleConfig.RegisterBundles(BundleTable.Bundles); } using System.Web.Mvc;