asp.net-web-api-routing

Multiple Routes on a Controller

帅比萌擦擦* 提交于 2019-12-03 01:21:14
Was wondering if it was possible to have more than one route pointing to a WebApi controller? For example I will like to have both http://domain/calculate and http://domain/v2/calculate pointing to the same controller function? 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.SuppressDefaultHostAuthentication(); config.Filters.Add(new HostAuthenticationFilter(OAuthDefaults.AuthenticationType)); // Web API routes config.MapHttpAttributeRoutes();

+ (plus) sign in Web API routing

大兔子大兔子 提交于 2019-12-02 22:34:22
I'm working with an asp.net web api project, and I have to pass an mobile number through a post. But i cannot return a plus sign. my route: config.Routes.MapHttpRoute( name: "SmsRoute", routeTemplate: "rest/sms/{country}/{company}/phone/{mobilenumber}", defaults: new { controller = "Sms", action = "PostSms" }); controller: public HttpResponseMessage PostSms(string country, string company, string mobilenumber) { return Request.CreateResponse( HttpStatusCode.Created ); } When I run this post method on fiddler: http://index.html/rest/sms/se/company/phone/46700101010/messages/out I'm getting this

Web API routing with multiple parameters

核能气质少年 提交于 2019-12-02 19:01:06
I'm trying to work out how to do the routing for the following Web API controller: public class MyController : ApiController { // POST api/MyController/GetAllRows/userName/tableName [HttpPost] public List<MyRows> GetAllRows(string userName, string tableName) { ... } // POST api/MyController/GetRowsOfType/userName/tableName/rowType [HttpPost] public List<MyRows> GetRowsOfType(string userName, string tableName, string rowType) { ... } } At the moment, I'm using this routing for the URLs: routes.MapHttpRoute("AllRows", "api/{controller}/{action}/{userName}/{tableName}", new { userName=

Can anyone explain CreatedAtRoute() to me?

血红的双手。 提交于 2019-12-02 16:26:51
From the template for Web API 2, a post method is always like this: [ResponseType(typeof(MyDTO))] public IHttpActionResult PostmyObject(MyDTO myObject) { ... return CreatedAtRoute("DefaultApi", new { id = myObject.Id }, myObject); } I don't understand this CreatedAtRoute() method. Can anyone explain the CreatedAtRoute() method to me? see sharper The CreatedAtRoute method is intended to return a URI to the newly created resource when you invoke a POST method to store some new object. So if you POST an order item for instance, you might return a route like 'api/order/11' (11 being the id of the

Attribute vs Conventional Routing

我们两清 提交于 2019-12-01 11:39:25
Q1: So this article says attribute routing is more favourable than conventional routing for api versioning. It's not clear to me the reasons behind such claim because to me in order to support these: /api/v1/products /api/v2/products all you need to do is to define two routes: routes.MapHttpRoute("V1", "api/v1/products", new {controller = "V1Controller", action = "ListProducts"}); routes.MapHttpRoute("V2", "api/v2/products", new {controller = "V2Controller", action = "ListProducts"}); Can something share some insight? Q2: this article says one issue with conventional routing is the order of

Attribute vs Conventional Routing

▼魔方 西西 提交于 2019-12-01 09:38:43
问题 Q1: So this article says attribute routing is more favourable than conventional routing for api versioning. It's not clear to me the reasons behind such claim because to me in order to support these: /api/v1/products /api/v2/products all you need to do is to define two routes: routes.MapHttpRoute("V1", "api/v1/products", new {controller = "V1Controller", action = "ListProducts"}); routes.MapHttpRoute("V2", "api/v2/products", new {controller = "V2Controller", action = "ListProducts"}); Can

Multiple GET's in Web API calling wrong action

喜你入骨 提交于 2019-12-01 09:18:24
问题 I have a Web API , that looks like the following... public class LeaguesController : ApiController { //api/Leagues/active/1 //api/Leagues/complete/1 //api/Leagues/both/1 [GET("api/Leagues/{type}/{id}")] public List<Competition> Get([FromUri]int id, [FromUri]CompetitionManager.MiniLeagueType type) { return CompetitionManager.GetUsersMiniLeagues(id, true, type); } //api/Leagues/GetMiniLeagueTable/3 [GET("api/Leagues/GetMiniLeagueTable/{id}")] public List<SportTableRow> GetMiniLeagueTable(

How to redirect to action in ASP.NET Core WebAPI?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-01 08:13:24
I've got two actions in my ASP.NET Core Web API application's controller: [HttpGet("get-all")] public IActionResult GetAll() { ... } and [HttpDelete("{id}")] public IActionResult Delete(int id) { ... return RedirectToAction("GetAll"); } Delete action always redirects to itself and never to GetAll . Why so? In the same time similar redirect from Post action works ok. Can't find any docs on the subject. Any help? Have you tried to use RedirectToActionResult? Like this (change ControllerName with your actual Controller's name ): RedirectToActionResult("GetAll", "ControllerName", null);

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

别等时光非礼了梦想. 提交于 2019-12-01 08:05:25
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 particular Controller. Here goes nothing: I have a Web API ("MVC") project. Really, though, this server

How to redirect to action in ASP.NET Core WebAPI?

无人久伴 提交于 2019-12-01 06:16:10
问题 I've got two actions in my ASP.NET Core Web API application's controller: [HttpGet("get-all")] public IActionResult GetAll() { ... } and [HttpDelete("{id}")] public IActionResult Delete(int id) { ... return RedirectToAction("GetAll"); } Delete action always redirects to itself and never to GetAll . Why so? In the same time similar redirect from Post action works ok. Can't find any docs on the subject. Any help? 回答1: Have you tried to use RedirectToActionResult? Like this (change