asp.net-web-api-routing

Multiple Controller Types with same Route prefix ASP.NET Web Api

隐身守侯 提交于 2019-11-26 12:43:02
问题 Is it possible to separate GETs and POSTs into separate API Controller types and accessing them using the same Route Prefix? Here are my controllers: [RoutePrefix(\"api/Books\")] public class BooksWriteController : EventStoreApiController { [Route(\"\")] public void Post([FromBody] CommandWrapper commandWrapper){...} } [RoutePrefix(\"api/Books\")] public class BooksReadController : MongoDbApiController { [Route(\"\")] public Book[] Get() {...} [Route(\"{id:int}\")] public Book Get(int id) {..

Post parameter is always null

馋奶兔 提交于 2019-11-26 12:06:55
Since upgrading to RC for WebAPI I'm having some real odd issue when calling POST on my WebAPI. I've even gone back to the basic version generated on new project. So: public void Post(string value) { } and calling from Fiddler: Header: User-Agent: Fiddler Host: localhost:60725 Content-Type: application/json Content-Length: 29 Body: { "value": "test" } When I debug, the string "value" is never being assigned to. It's just always NULL. Anyone having this issue? (I first saw the issue with a more complex type) The problem is not only bound to ASP.NET MVC 4, the same problem occurs for a fresh ASP

Is there a default verb applied to a Web API ApiController method?

我与影子孤独终老i 提交于 2019-11-26 11:21:55
问题 I\'ve been looking at the code (in https://github.com/patelsan/WebAPIAuthentication) from this article: http://www.codeproject.com/Articles/630986/Cross-Platform-Authentication-With-ASP-NET-Web-API. It\'s pretty good and seems to work fine. There are very few articles that explain this kind of token authentication, but this is the best I\'ve seen. Note that I\'m new to this technology and there\'s much to learn. So, I noticed that the UsersController has this code: public class

Query string not working while using attribute routing

六眼飞鱼酱① 提交于 2019-11-26 10:24:56
问题 I\'m using System.Web.Http.RouteAttribute and System.Web.Http.RoutePrefixAttribute to enable cleaner URLs for my Web API 2 application. For most of my requests, I can use routing (eg. Controller/param1/param2 ) or I can use query strings (eg. Controller?param1=bob&param2=mary ). Unfortunately, with one of my Controllers (and only one), this fails. Here is my Controller: [RoutePrefix(\"1/Names\")] public class NamesController : ApiController { [HttpGet] [Route(\"{name}/{sport}/{drink}\")]

FromBody string parameter is giving null

放肆的年华 提交于 2019-11-26 09:03:56
问题 This is probably something very basic, but I am having trouble figuring out where I am going wrong. I am trying to grab a string from the body of a POST, but \"jsonString\" only shows as null. I also want to avoid using a model, but maybe this isn\'t possible. The piece of code that I am hitting with PostMan is this chunk: [Route(\"Edit/Test\")] [HttpPost] public void Test(int id, [FromBody] string jsonString) { ... } Maybe it is something I am doing incorrectly with postman, but I have been

Routing with multiple Get methods in ASP.NET Web API

青春壹個敷衍的年華 提交于 2019-11-26 06:57:15
问题 I am using Web Api with ASP.NET MVC, and I am very new to it. I have gone through some demo on asp.net website and I am trying to do the following. I have 4 get methods, with the following signatures public List<Customer> Get() { // gets all customer } public List<Customer> GetCustomerByCurrentMonth() { // gets some customer on some logic } public Customer GetCustomerById(string id) { // gets a single customer using id } public Customer GetCustomerByUsername(string username) { // gets a

Attribute routing and inheritance

 ̄綄美尐妖づ 提交于 2019-11-26 04:45:35
问题 I am playing around with the idea of having a base controller that uses a generic repository to provide the basic CRUD methods for my API controllers so that I don\'t have to duplicate the same basic code in each new controller. But am running into problems with the routing attribute being recognized when it\'s in the base controller. To show exactly what the problem I\'m having I\'ve created a really simple WebAPI controller. When I have a Get method in the main Controller and it inherits

Custom method names in ASP.NET Web API

与世无争的帅哥 提交于 2019-11-26 04:06:32
问题 I\'m converting from the WCF Web API to the new ASP.NET MVC 4 Web API. I have a UsersController, and I want to have a method named Authenticate. I see examples of how to do GetAll, GetOne, Post, and Delete, however what if I want to add extra methods into these services? For instance, my UsersService should have a method called Authenticate where they pass in a username and password, however it doesn\'t work. public class UsersController : BaseApiController { public string GetAll() { return \

Multiple actions were found that match the request in Web Api

£可爱£侵袭症+ 提交于 2019-11-26 02:28:07
问题 I keep getting this error when I try to have 2 \"Get\" methods Multiple actions were found that match the request: webapi I been looking around at the other similar questions about this on stack but I don\'t get it. I have 2 different names and using the \"HttpGet\" attribute [HttpGet] public HttpResponseMessage Summary(MyVm vm) { return null; } [HttpGet] public HttpResponseMessage FullDetails() { return null; } 回答1: Your route map is probably something like this: routes.MapHttpRoute( name: