asp.net-web-api-routing

WebApi routing - many POST methods

纵饮孤独 提交于 2019-12-23 01:41:55
问题 I have WebAPI 2 application. How can I specify 2 or more POST methods? I have the following WebApiConfig: public static void Register(HttpConfiguration config) { config.SuppressDefaultHostAuthentication(); config.Filters.Add(new HostAuthenticationFilter(OAuthDefaults.AuthenticationType)); // Web API routes config.MapHttpAttributeRoutes(); config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional } ); } and API

WebApi routing - many POST methods

笑着哭i 提交于 2019-12-23 01:41:49
问题 I have WebAPI 2 application. How can I specify 2 or more POST methods? I have the following WebApiConfig: public static void Register(HttpConfiguration config) { config.SuppressDefaultHostAuthentication(); config.Filters.Add(new HostAuthenticationFilter(OAuthDefaults.AuthenticationType)); // Web API routes config.MapHttpAttributeRoutes(); config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional } ); } and API

Create Web API for request with code and term query parameters

安稳与你 提交于 2019-12-22 18:12:40
问题 In ASP.NET MVC4 application Json Web api needs to be created to serve requests with term and code url parameters like: http://myapp.com/api/customers returns all customers http://myapp.com/api/customers?term=partofname returns 0 .. n customers and http://myapp.com/api/customers?code=customercode returns 1 customer always code is customer id which can contain / and other characters which are not allowed in url passed to windows http server by http.sys in windows kernel API controller below is

Routing of file-like names in Asp.NET WebApi

梦想的初衷 提交于 2019-12-22 09:57:53
问题 Is it possible to add a route in the ASP.NET Web API routing configuration that allows handling URLs that look a bit like file names? I tried adding the following entry in WebApiConfig.Register() , but that didn't work (using URI api/foo/0de7ebfa-3a55-456a-bfb9-b658165df5f8/bar.group.json ): config.Routes.MapHttpRoute( name: "ContextGroupFile", routeTemplate: "api/foo/{id}/{filetag}.group.json", defaults: new { controller = "foo", action = "getgroup"} ); The following did work though (it

What is the different between System.Web.Http.HttpPut Vs System.Web.Mvc.HttpPut

99封情书 提交于 2019-12-22 04:44:10
问题 What is the different between System.Web.Http.HttpPut and System.Web.Mvc.HttpPut ? Using [HttpPut] on the Web API project results the error 405 - The requested resource does not support http method 'PUT'. 回答1: They belong to two different frameworks. The pipeline flow of each is looking for specific attributes that belong to their respective namespaces. The routing engine for the respective frameworks are not aware of the other so if a Web API attribute is used on a MVC action it would be

ASP.NET 5 HTML5 History

怎甘沉沦 提交于 2019-12-22 04:23:19
问题 I'm upgrading my project to ASPNET5. My application is a AngularJS Web App that uses HTML5 Url Routing ( HTML5 History API ). In my previous app I used the URL Rewrite IIS Module with code like: <system.webServer> <rewrite> <rules> <rule name="MainRule" stopProcessing="true"> <match url=".*" /> <conditions logicalGrouping="MatchAll"> <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> <add input="{REQUEST

How to match web api 2 route with forward slashes in request parameters?

蓝咒 提交于 2019-12-22 03:52:14
问题 I'm using Web API 2 attribute routing and I have a request which is not resolved properly. [Route("~/foo/{bar?}")] public void Get(string bar); My request it's like: mydomain.me/foo/abc/def I expect to receive bar as "abc/def" but the forward slash messes the route match. Replacing the forward slash with "%2F" doesn't solve the problem. 回答1: You could use wildcard based matching like below: [Route("~/foo/{*bar}")] public string Get(string bar) 来源: https://stackoverflow.com/questions/20034227

Web Api HTTPPost not accepting int

▼魔方 西西 提交于 2019-12-22 03:47:21
问题 I am trying to just pass in body a int and it does not work Why do I need to create a class with a property of type int ? (then it works) WORKS [HttpPost] [Route("api/UpdateMainReversed")] public IHttpActionResult UpdateMainVerified(DataAccess.Entities.RequestMain mainValues) { ....} DO NOT WORK [HttpPost] [Route("api/UpdateMainReversed")] public IHttpActionResult UpdateMainVerified(int mainId) { ....} Testing with Postman http://localhost:13497/api/UpdateMainReversed Body { "mainId" : 1615 }

Different RoutePrefix, same controller name

陌路散爱 提交于 2019-12-22 01:39:20
问题 I'm having a problem with splitting my web-api application into different areas (not mvc areas), using namespaces and RoutePrefix The application is hosted using Owin Self Host, and in my Startup class I have the following. HttpConfiguration config = new HttpConfiguration(); config.MapHttpAttributeRoutes(); app.UseWebApi(config); And my two controllers that I tested with [RoutePrefix("api/test")] public class TestController : ApiController { [Route("")] public IHttpActionResult Get() { return

How do I get Web API / Castle Windsor to recognize a Controller?

旧时模样 提交于 2019-12-21 23:00:21
问题 I found out why the placeholder "Home Controller" was getting called here I commented out the reference to HomeController in RouteConfig.cs and added a Controller that I want it to call instead: public class RouteConfig { public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); //If get 404 error re: favicon, see http://docs.castleproject.org/(X(1)S(vv4c5o450lhlzb45p5wzrq45))/Windsor.Windsor-tutorial-part-two-plugging-Windsor-in.ashx or