asp.net-web-api-routing

Web API Routing - Only actions with a URI parameter work

旧城冷巷雨未停 提交于 2019-12-13 00:09:31
问题 I had a web API project that was working fine. I merged it with an MVC project, and now only the actions with a URI parameter work. All other actions end up with a 404 Not Found where even the controller is not found. Here's what I have in WebApiConfig (standard stuff): public static class WebApiConfig { public static void Register(HttpConfiguration config) { // Web API configuration and services // Configure Web API to use only bearer token authentication. config

How To Register RouteConstraints in MVC6

随声附和 提交于 2019-12-12 10:54:25
问题 There are numerous tutorials on how to create RouteConstraints in previous MVC versions: Registering ASP.NET MVC Route Constraints for Attribute Routing Constraints in Attribute-based Routing MVC5 How does this work with MVC6, specifically registering the custom route constraint, so it can be used in attributes of ApiController Actions? I have created a custom route constraint, called NonEmptyGuid, which really just makes sure a non-empty Guid is used as the parameter of a GET Action: public

Route not recognised in MVC 4 WebAPI

谁说胖子不能爱 提交于 2019-12-12 10:26:08
问题 I haven't used the ASP.NET WebAPI much although I have used routes in straight MVC. Obviously I'm doing something wrong, perhaps someone can help? I have one controller called UsersController and two methods on it, Register and Details, both take two string parameters and return a string, both marked as HttpGet. Originally I started with two route mappings in WebApiConfig.cs: config.Routes.MapHttpRoute( name: "TestApi", routeTemplate: "api/{controller}/{action}/{userId}/{key}" ); config

Why is this Post operation failing?

邮差的信 提交于 2019-12-12 06:47:57
问题 Based on this, for my Web API project, I'm using this code on the client: private void AddDepartment() { int onAccountOfWally = 42; string moniker = "Billy Bob"; Cursor.Current = Cursors.WaitCursor; try { string uri = String.Format("http://platypi:28642/api/Departments/{0}/{1}", onAccountOfWally, moniker); var webRequest = (HttpWebRequest)WebRequest.Create(uri); webRequest.Method = "POST"; var webResponse = (HttpWebResponse)webRequest.GetResponse(); if (webResponse.StatusCode !=

Testing ASP.NET Web API POST and Parameterless GET Routes with WebApiContrib.Testing

醉酒当歌 提交于 2019-12-12 04:05:37
问题 I am trying to set up some route tests using the WebApiContrib.Testing library. My get tests (like this) work fine... [Test] [Category("Auth Api Tests")] public void TheAuthControllerAcceptsASingleItemGetRouteWithAHashString() { "~/auth/sjkfhiuehfkshjksdfh".ShouldMapTo<AuthController>(c => c.Get("sjkfhiuehfkshjksdfh")); } I am rather lost on the post test - I currently have the following which fails with a NotImplementedException... [Test] [Category("Auth Api Tests")] public void

Set WebApi 2 routes

我是研究僧i 提交于 2019-12-12 03:29:51
问题 I'm fairly new to WepApi2 and creating restfull webservice, but I get the hang of most of it. Recently, I started developing a new WebApi2 where I encounter that some of my queries required some unesacapable characters, specially the slash and inverted slash ones. I read several tutorials and questions here about the matter, but none would suffice me, so I ended up to setting my api queries like this http://host/controler/action/?param1=x&param2=y Everything works perfect. I had to setup the

Why is my Web API call returning “No action was found on the controller 'DPlatypus' that matches the request”?

浪尽此生 提交于 2019-12-12 02:35:09
问题 I am trying to create the simplest possible ASP.NET Web API app that incorporates and uses DI with Castle Windsor. I have a working app that is more complicated, and I have tried to copy the "bare bones" from it (as little as possible and still have it work). The working app has this URL ("Home Page"): http://localhost:28642/ Entering this: http://shannon2:28642/api/Departments/Count ...in my browser returns the data I want, from the Departments Controller. However, the new/simple/non-working

Why is HomeController getting referenced, and how do I support it (assuming I should)?

限于喜欢 提交于 2019-12-12 01:49:56
问题 This is sort of a Helleresque (Catch-22) situation; or perhaps more appropriately "unrepositoried if I do, and unrepositoried if I don't" With this Castle Windsor Controller Factory: public class WindsorControllerFactory : DefaultControllerFactory { private readonly IKernel _kernel; public WindsorControllerFactory(IKernel kernel) { _kernel = kernel; //According to http://docs.castleproject.org/Windsor.Typed-Factory-Facility.ashx, might need this: //_kernel.AddFacility<TypedFactoryFacility>();

WebAPI : Min/max double for RouteAttribute

*爱你&永不变心* 提交于 2019-12-12 01:37:41
问题 I have the following API method: [Route("GetEditorialRequestsByCoordinates/{lat:double}/{lng:double}")] [AutomapperExceptionApiFilterAttribute] public HttpResponseMessage GetEditorialRequestsByCoordinates(double lat, double lng) { } it works fine for request like: GET /v1/api/request/GetEditorialRequestsByCoordinates/48.999/2.777/ But I want to add limit (minimum and maximum) for lat and lng. Follow this article: http://www.asp.net/web-api/overview/web-api-routing-and-actions/attribute

Can I programmatically determine the database “context” to use based on user credentials?

北战南征 提交于 2019-12-11 21:18:51
问题 This is a followup to the question here, where the answer seems to refer to an overly-complicated and overly-specific (EF, which I'm not using - not even using an ORM). There has to be a more straightforward way around this common scenario than the smoke, mirrors, and sorcery hinted at in that answer. Note: I encased "context" in parenthesis because I'm not using EF, so it is not a literal "dbcontext" that I'm talking about here. So I got to wondering: Could I set a global variable for each