asp.net-web-api-routing

Net Web 4.5.1 routing anything not authenticated

我只是一个虾纸丫 提交于 2019-12-11 20:32:30
问题 Using Net Web 4.5.1 Started off trying to configure a rule on the default document (i.e. index.html): routes.MapPageRoute( "Default", "", "~/Statics/anybody.html" ); If during debug locally I want (without extensions) http://localhost:52065 to go to http://localhost:52065/Statics/anybody.html Down the road I want any request that isn't authorized to be directed to the splash page (i.e. /Statics/anybody.html). 回答1: I'm hesitant to post this, but, this is how you could do it: public class

WebApi help and multipe routes

百般思念 提交于 2019-12-11 12:54:25
问题 I hav a web api project (C#, asp.net MVC) where I need to be able to call actions both, using template api/{controller}/{action}/{id} and api/{controller}/{id}. To do this, I've added 2 routes for api controller: config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{action}/{id}", defaults: new { id = RouteParameter.Optional }, constraints: new { action = @"^[a-zA-Z]+$" } ); config.Routes.MapHttpRoute( name: "RestFull", routeTemplate: "api/{controller}/{id}",

ASP.NET Core Web API: Routing by method name?

我只是一个虾纸丫 提交于 2019-12-11 12:52:46
问题 I remember from ASP.NET Web API that it's sufficient to prefix Web API REST method names with HTTP commands (e.g. GetList() => HTTP GET , Delete() => HTTP DELETE ) to have incoming calls appropriately routed. I also remember that in ASP.NET Web API parameter matching takes place so that even Get(int id) and Get(int id, string name) get automatically and appropriately routed without requiring any attributes. public class MyController { public ActionResult Get(int id) => ... public ActionResult

Should I use “[FromBody]” values or custom params when responding to an HTTP Post call in a Web API app?

Deadly 提交于 2019-12-11 12:16:36
问题 Is POST the right HTTP method/verb to use for telling the server which criteria to use to retrieve data and then save it locally? I want to send an URL from a client (Windows Forms) app/util to my Web API app to tell it to retrieve data via a Stored Proc, then store the results in a local table. No data is returned to the caller, it's just a notification to do some work. To prepare for this, I added a new route to WebApiConfig: // Some reports (monthly) only need a begindate, such as "201509"

Web API Routing - No action was found on the controller that matches the request

落爺英雄遲暮 提交于 2019-12-11 10:46:43
问题 Ok web api routing fun. my web api route config is below. the geocoding and info routes are performing great. And I'm confused why the search one is not following suite. /* ==Geocoding Endpoints== */ config.Routes.MapHttpRoute( name: "v1_GeocodeApi", routeTemplate: "api/v{version}/{controller}/{street}/{zone}", defaults: new { action = "get", controller = "Geocode", version = "1" }); config.Routes.MapHttpRoute( name: "v1_GeocodeMultipleApi", routeTemplate: "api/v{version}/{controller}

Fallback controller route in ASP.NET Web API v2

早过忘川 提交于 2019-12-11 09:47:03
问题 I'm building an offline web app that uses the path string for client-side URLs. There are several (attribute-based) routes that map to dedicated controllers for resources, API calls, etc.. For example: /myapp/api/... /myapp/resources/... I then want all requests that do not match one of these patterns to be routed to my bootstrap HTML page, which I currently serve via a dedicated controller. So, for example, the following requests need to end up at the bootstrap HTML page: /myapp/customers/..

Configuring Route to allow dot as extension?

不想你离开。 提交于 2019-12-11 07:28:55
问题 Imagine the following: client app, which no one has control over, calls Web API methods but each of these methods ends in extensions such as : /api/{controller}/{method}.ab How is it possible to configure the ASP.NET web API, for a specific controller, to allow extensions for the method being called but also allow the existing default controllers to continue working? For instance if we have a method call GetCustomer , the client app will call GetCustomer.ab but want that call to be routed to

Multiple GET no good w/ Attribute Routing?

眉间皱痕 提交于 2019-12-11 06:48:34
问题 This is supposed right: /api/MyDataController.cs public class MyDataController: ApiController { [HttpGet] [Route("GetOne")] public IHttpActionResult GetOne() { } // works w/o GetTwo [HttpGet] [Route("GetTwo")] public IHttpActionResult GetTwo() { } } .js $http({method: 'GET', url: '/api/MyData/GetOne'})... //works w/o GetTwo $http({method: 'GET', url: '/api/MyData/GetTwo'})... Same as this post, API version is <package id="Microsoft.AspNet.WebApi" version="5.2.3" targetFramework="net461" />

Asp.NET Web Api - multiple apis/namespaces

无人久伴 提交于 2019-12-11 03:21:44
问题 In my MVC4 web app, I need to support multiple APIs. I looked around and apparently in Web API, Controllers with same name in different name spaces is not supported. What are my options? Ex: I want to be able to provide to my API consumers links like, http://domainurl/api/api1/Students... http://domainurl/api/api2/Students... A Student Resource in api1 can be totally different from the one in api2. In such cases what is the best approach? I do not want to make it a single api and handle it

pass string array as parameter to asp.net mvc webapi method

可紊 提交于 2019-12-11 02:59:16
问题 I am using webapi2 and here is my client side code var tbody = $('#files-table').find('tbody'); // tbody where all rows exists var sortOrder = $(tbody).sortable('toArray').toString(); // geting ids of all rows var updateSortOrder = $.ajax({ url: baseUrl + 'mycontroller/updateimagesorder', dataType: 'json', traditional: true, contentType: 'application/json', data: JSON.stringify({ "sortOrder": sortOrder.split(',') }), type: 'PUT' }); updateSortOrder.done(function (result) { closeModel('images