asp.net-web-api-routing

How do I connect the various pieces of my Web API Castle Windsor DI code?

℡╲_俬逩灬. 提交于 2019-12-01 05:53:08
问题 How do I connect the various pieces of my Web API Castle Windsor DI code so that the Controller's routing selects the correct interface implementation? Note : After several false starts/dead ends and partial victories (here and here and here), I am going to bountify this ASAP for the maximum 500 points. But I'm only going to award a really good answer - IOW, one that is clear enough that I can understand it and "plug it in" to my project so that I can hook a given concrete class to a

Where is the “magic” happening when a Controller instantiates the correct implementation of the Interface in Web API DI?

喜你入骨 提交于 2019-12-01 05:51:58
问题 It seems to me that somewhere a rabbit is being pulled out of a hat when it comes to DI in Web API Controllers. I grok that: 0) The Controller in a Web API project can be called with various classes to be instantiated, all of which implement the interface on which the Controller depends. e.g., with this Controller code: private readonly IDepartmentRepository _deptsRepository; public DepartmentsController(IDepartmentRepository deptsRepository) { if (deptsRepository == null) { throw new

web api routing and http post [duplicate]

北慕城南 提交于 2019-12-01 04:07:39
This question already has an answer here: WebAPI - Attribute Routing POST not working with WebAPI Cors? 1 answer I'm building an API using WEB API 2. I have the following API controller: [RoutePrefix("api/account")] public class AccountController : ApiController { [Route("login")] [HttpPost] public IHttpActionResult AuthenticateUser(string username, string password) { if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(password)) { return BadRequest("You must submit username and password"); } if (!Membership.ValidateUser(username, password)) { return BadRequest("Incorrect username or

web api get route template from inside handler

谁都会走 提交于 2019-12-01 03:54:12
I searched a lot before putting the questions here but the more I search the more confused I get. So I have created an handler and I am trying to get the route like this: public class ExecutionDelegatingHandler : DelegatingHandler { protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) { if (securityAuthority.VerifyPermissionToExecute(request.GetRouteData().Route.RouteTemplate, request.Headers)) { return base.SendAsync(request, cancellationToken); } else { httpResponseMessage.StatusCode = HttpStatusCode.Unauthorized; } } }

Can I have Multiple Get Methods in ASP.Net Web API controller

走远了吗. 提交于 2019-12-01 03:10:19
问题 I want to implement multiple Get Methods, for Ex: Get(int id,User userObj) and Get(int storeId,User userObj) Is it possible to implement like this, I don't want to change action method name as in that case I need to type action name in URL. I am thinking of hitting the action methods through this sample format ' //localhost:2342/ ' which does not contains action method name. 回答1: Basically you cannot do that, and the reason is that both methods have same name and exactly the same signature

web api get route template from inside handler

为君一笑 提交于 2019-12-01 00:43:53
问题 I searched a lot before putting the questions here but the more I search the more confused I get. So I have created an handler and I am trying to get the route like this: public class ExecutionDelegatingHandler : DelegatingHandler { protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) { if (securityAuthority.VerifyPermissionToExecute(request.GetRouteData().Route.RouteTemplate, request.Headers)) { return base.SendAsync(request,

Web Api 2.2 OData V4 Function Routing

可紊 提交于 2019-11-30 11:39:01
I have a Web Api 2.2 project working with OData v4. The normal EntitySet configuration is working as desired with all http verbs. Where I am having a problem is trying to expose a custom function. I started off trying to do something different than the standard examples, but I have backed all the way up to just trying to getting a basic example function working. Here is my startup config (straight from the MS examples): using System; using System.Collections.Generic; using System.Linq; using System.Web.Http; using System.Web.OData.Builder; using System.Web.OData.Extensions; namespace Test

asp.net webapi 2 attribute routing not working

ぃ、小莉子 提交于 2019-11-30 10:35:19
问题 I have visual studio 2012 installed with mvc4 using .net framework 4.5. Now I want to use webapi2 with attribute writing and i want my hlep page show all the endpoints properly. In my solution i added a new mvc4 base emtpy project and using nuget i upgraded to mvc5 and then i have installed webapi2 packages. lastly i have installed help package for webapi2. now when i use routeprefix I cant see any content on help page and when i try to access my webapi endpoint in browsers it throws

Custom httphandler and routehandler with ASPNET MVC 4 and webapi

坚强是说给别人听的谎言 提交于 2019-11-30 09:02:53
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 following the tutorial here public class MvcSecurityRouteHandler:IRouteHandler { public System.Web

Attribute routing with optional parameters in ASP.NET Web API

我的未来我决定 提交于 2019-11-30 07:02:44
问题 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