FAQ Database Discussion Community


WebApiConfig.Register Clears routes defined by RouteConfig.RegisterRoutes apon deployment

asp.net-mvc,asp.net-mvc-4,iis,asp.net-mvc-routing,asp.net-web-api-routing
I'm on struggle street here, When I try to add API controllers it seems to destroy all my MVC base routes and area routes. On my application start I call protected void Application_Start() { AreaRegistration.RegisterAllAreas(); WebApiConfig.Register(GlobalConfiguration.Configuration); //FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); Util.RazorDebuggingSetup(); BundleConfig.RegisterBundles(BundleTable.Bundles); } using System.Web.Mvc; An example of an area config: namespace...

WebAPI routing cuts wildcard parameter on a question mark

c#,asp.net-web-api,asp.net-web-api-routing
I have a route in controller that should match everything in part of url and put it into string parameter. What I have is: [Route("api/proxy/{proxyId}/{*parameter}")] public Task<HttpResponseMessage> Mediate(int proxyId, string parameter) and for an unknown url, for example: http://localhost/api/proxy/1/test?a=1&b=2 I would like "parameter" variable to contain: test?a=1&b=2 Instead, it contains:...

Cannot get parameter when sending a post request

javascript,asp.net,ajax,asp.net-web-api,asp.net-web-api-routing
I'm using attribute routing. I cannot get parameters from HTTP body, can anyone please tell what's wrong here. My ConnectionID Class has a property called CValue. $('#btn').click(function () { $.ajax({ type: "POST", url: "http://localhost:49289/api/Resolver/StartRun", data: { "CValue": connectionID }, success: success, dataType: "json" }); }); [Route("api/Resolver/StartRun")] [HttpPost] public async Task<string>...

using Web API attribute routing and RoutePrefix

asp.net-web-api,routing,web-api,asp.net-web-api-routing
When using web api, how does one call the proper routing methods if you use [RoutePrefix()] Say you have something like "MyReallyLongNamedClassController". the default route would be http:...com/api/MyReallyLongNamedClass. The application then goes by methods named Get, Post, Put, etc (unless of course using verb decorators). If I put a route...

How do I only display methods that belong to a controller specified by the URL

c#,asp.net-mvc,asp.net-web-api,asp.net-web-api-routing,asp.net-web-api-helppages
I am working on customizing the ASP.NET Web API help pages. I am looking for the best approach to display methods that belong to a controller specified by the URL. My controllers are all prefixed with "ws_". I have added an entry to my RouteConfig to recognize URLs containing the...

WebAPI Routing with Area - 404 Error when missing optional parameter

asp.net-mvc,asp.net-web-api,asp.net-web-api-routing
I'm running into a 404 Error when I try to call my WebAPI controller without an optional parameter. I've tried reordering the route initializion commands in the Global.asax.cs to no avail. The WebAPI is in an area and I comment out the area's routing information so it doesn't find that...

Web API controller with two PUT methods throw an InvalidOperationException

c#,asp.net,asp.net-web-api,asp.net-web-api-routing
I'm developing an ASP.NET Web Api 2.2 app with .NET Framework 4.5.1 and C#. I have a controller with this method: public HttpResponseMessage Get( string productCode, byte codeLevel, string productionOrderName, string batchName, string lineName, int quantity) { And this is how I have configured its route on WebApiConfig: config.Routes.MapHttpRoute( name:...

Cannot cast System.Web.Http.WebHost.Routing.HostedHttpRoute to System.Web.Http.Routing.IHttpRoute

c#,casting,asp.net-web-api2,asp.net-web-api-routing
After updating ASP.NET Web API to 2.2 (from nuget package version 4.0 to 5.2) for a Web API solution, I can no longer cast an object of type System.Web.Http.WebHost.Routing.HostedHttpRoute to System.Web.Http.Routing.IHttpRoute. According to this source of HostedHttpRoute, it implements IHttpRoute so the cast should work. However, this source must be...

Route parameter with slash “/” in URL

asp.net-web-api,routing,asp.net-web-api2,asp.net-web-api-routing,attributerouting
I know you can apply a wildcard in the route attribute to allow / such as date input for example: [Route("orders/{*orderdate}")] The problem with wildcard is only applicable to the last paramter in URI. How do I solve the issue if want to have the following URI: [Route("orders/{orderdate}/customers")] ? EDIT:...

Using '.' in Web Api using Attribute Routing is giving 404 error

asp.net-web-api,routes,asp.net-web-api2,asp.net-web-api-routing,attributerouting
I am using Routing Attribute to try to send a string via url to my web Api. I have a Route defined as [Route("Search/{searchText}")] I am expecting a string value as searchText. It seems to be working fine but I am getting an error if there is a '.' in...

Different Web API 2 controllers when using attribute routing

c#,asp.net,asp.net-web-api-routing
I'm building a prototype for a RESTful API using ASP.NET Web API 2. Fo simplictiy let's assume I have three entities: customers, licences and users. Each customer has a set of licences and users. Semantically it seems to me the resource URIs should look like this: myurl/api/customers for accessing all...

Can you use a regex in .NET WebApi Route URI For API Versioning

asp.net,.net,asp.net-mvc,asp.net-web-api,asp.net-web-api-routing
In MVC and WebApi you can add parameter constraints to your routes (see http://www.asp.net/web-api/overview/web-api-routing-and-actions/attribute-routing-in-web-api-2#constraints). You can even use regular expressions for the parameter constraints. However, I'm wondering if it's possible to use regular expressions to handle API versioning where many routes could/should route to the same action. For example, I'm...

WebAPI 2.0 Post and Delete Routes

c#,asp.net-web-api,asp.net-web-api-routing
I have two actions on the same controller, with identical routes, but separate HttpMethod requirements (POST vs DELETE). [AllowAnonymous] public class TestController : ApiController { [Route("~/api/test")] [HttpDelete] public IHttpActionResult Endpoint1() { return this.Ok("endpoint1"); } [Route("~/api/test")] [HttpPost] public IHttpActionResult Endpoint2() { return this.Ok("endpoint2"); } } This is all fine -- both...

Asp.NET Web API Displaying all controller's routes

asp.net,asp.net-web-api,asp.net-web-api-routing
Is there a way to display all the available services that the application exposes via Web Api actions? For example when a user goes to http://someurl/api/ he will get a list of all the available services, their descriptions and the required parameters? I remember that I've seen this once but...

how to forward a link with URI to another link with the same URI

html,asp.net,html5,asp.net-mvc-4,asp.net-web-api-routing
My program directs users to a webpage with their username and password. E.g. http://example.html?username=username&password=password. Now I created another page in asp.net and I want some code on example.html to redirect the link to http://example.aspx?username=username&password=password. So what i want is to get the URI from the first url and direct it...

What's wrong with this route

c#,azure,asp.net-web-api-routing
Given the following: namespace Foo.Controllers { [RoutePrefix("api/route")] public class SnoconesFooBarController : BaseApiController { /// <summary> /// Asks for a new foo to be created to the given subnet with the specific bar named /// </summary> /// <param name="fooName"></param> /// <param name="uriString"></param> /// <returns></returns> [Route("newFoo/{fooName}")] public async Task<IHttpActionResult> PostNewFooForSpecificBar(string fooName, string...

Web API Returning a 405. Shouldn't it be a 404?

rest,asp.net-web-api,asp.net-web-api2,asp.net-web-api-routing
I've got a VendorsController that supports GET (by id) and POST (with a model). They are working as expected when called through the intended routes. However, I noticed that if I add an id to the POST route (ie add "/5" to "api/vendors"), I get a 405, with Response Body...

Nothing happens when Angular Href is clicked

angularjs,asp.net-web-api2,angularjs-routing,asp.net-web-api-routing
I am using Angular Routing with a webapi 2 controller. Although the default path loads with the correct data, when I click on an item in a list containing a link to a details page, no data is loaded. The browser shows what I believe to be the correct url...

WebApi Routing not working for Post

routing,asp.net-web-api2,asp.net-web-api-routing
My WebApiConfig has following routes // Web API routes config.MapHttpAttributeRoutes(); config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { controller = "Employee", action = "Get", id = RouteParameter.Optional } ); The Post WebApi method has got following Signatures [HttpPost] public IHttpActionResult Post(Employee emp) { ..... } When i try to call...

How to use the same route with different parameter types?

asp.net-web-api,asp.net-mvc-5,asp.net-mvc-routing,web-api,asp.net-web-api-routing
I have an Api controller with two different actions that take different parameter types. // GET: users/sample%40email.com [Route("users/{emailAddress}")] public IHttpActionResult GetUser(string emailAddress) // GET: users/1D8F6B90-9BD9-4CDD-BABB-372242AD9960 [Route("users/{reference}")] public IHttpActionResult GetUserByReference(Guid reference) Problem is multiple actions are found matching when I make a request to either. Looking at other answers I thought...

Modify and redirect for not found URl in web api

asp.net,angularjs,asp.net-web-api,asp.net-web-api-routing
I enabled Html5 mode in angular for my project witch convert my URl from A: qwe.com/#/products to B: qwe.com/products But the problem is in this case if user trying to directly go to B, server (web api) catch the Url and return not found error so I need a way...