attributerouting

Requested resource does not support http method “PUT”

帅比萌擦擦* 提交于 2019-12-08 19:58:44
问题 I'm using AttributeRouting with my Web API (MVC 4). Why does this work? [AcceptVerbs("PUT")] [PUT("api/v1/tokens/current")] public MemoryToken UpdateToken([FromBody] DeviceTokenViewModel viewModel) {...} And this one does not? [PUT("api/v1/tokens/current")] public MemoryToken UpdateToken([FromBody] DeviceTokenViewModel viewModel) {...} Error message: The requested resource does not support http method "PUT". Why do I have to explicitly accept the PUT verb? I'm just confused because something

Is it possible to select an Action with AttributeRouting in .NET MVC based on the Media Type of the Accept header?

天大地大妈咪最大 提交于 2019-12-08 19:34:16
问题 I want to select an Action of my Controller based on the Media Type requested in the Accept header. For example, I have a resource called a subject. Its assigned route is: GET /subjects/{subjectId:int} Normally, the browser is requesting text/html , which is fine. The default Media Formatter handles this great. Now, I have custom logic I want to perform when this same route is accessed with an accept header specifying application/pdf as the accepted Media Type. I could create a custom Media

Change route to username after registration

这一生的挚爱 提交于 2019-12-08 10:26:32
问题 I have followed the correct answer marked for this thread How to change route to username after logged in? and my requirement is exactly what the question says. However when I register a new user (I am using username instead of email) the redirection doesn't follow my custom route. For instance, when I register with username = Janet, the URL looks like localhost/?username=Janet and throws an error. But if I manually remove the "/?username=" and keep localhost/Janet then it shows the landing

AttributeRouting - Correct way of Getting the Action Name from RouteData

白昼怎懂夜的黑 提交于 2019-12-07 16:45:34
问题 I have recently started using attribute routing for my action methods and am struggling in getting the action name (and/or id) from the RouteData. Below is an example of how I use the attrubues like so: [Route( "Edit/{id:int}" )] public ActionResult Edit( int id ) { ... } Previously I used the following method as an extension of RouteData to retrieve the value public static string GetActionName( this RouteData routeData ) { return routeData.Values[ "Action" ] as string; } This used to return

ASP.net WebApi Multiple controller types were found that match the URL

≡放荡痞女 提交于 2019-12-06 07:01:10
I have added a new HttpPost route "api/export/error/" to my WebApi, using Attribute Routing, and I am getting an error: Multiple controller types were found that match the URL. This can happen if attribute routes on multiple controllers match the requested URL.\r\n\r\nThe request has found the following matching controller types: \r\nMyApp.Controllers.ExportErrorController\r\nMyApp.Controllers.ExportGeneratorController But I do not have the same routes in different controllers that i see; here are the only routes in those two controllers: ExportErrorController.cs [HttpGet] [Route( "api/export

Web Api Controller in other project, route attribute not working

风流意气都作罢 提交于 2019-12-05 13:51:46
问题 I have a solution with two projects. One Web Api bootstap project and the other is a class library. The class library contains a ApiController with attribute routing. I add a reference from web api project to the class library and expect this to just work. The routing in the web api is configured: config.MapHttpAttributeRoutes(); The controller is simple and looks like: public class AlertApiController:ApiController { [Route("alert")] [HttpGet] public HttpResponseMessage GetAlert() { return

MVC 5 AttributeRouting Catch All

a 夏天 提交于 2019-12-05 01:26:57
How do I create a catch all route with the new Attribute routing in MVC I tried this: [Route("{pagenode}", Order = 999)] But when I have a named route like [Route("contact"] I get the "Multiple controller types were found that match the URL. This can happen if attribute routes on multiple controllers match the requested URL." error. You can't do this with Attribute routing, do this the MVC4 way: Map a route in your routemapper like this: routes.MapRoute("RouteName","{*url}",new { controller = "YourFancyController", action = "YourAction" }); This will be your catch-all Route. If you would like

OWIN cannot run multiple apps in isolation using webapp.start

て烟熏妆下的殇ゞ 提交于 2019-12-05 01:20:33
问题 When I try and start two apps on different url's, I get problems with attribute routing middleware. If I have two similar routes in seperate apps but with different http methods web.api seems find only one of the methods. Microsoft.Owin.Hosting.WebApp.Start<Admin.Startup>("http://localhost:1000"); Microsoft.Owin.Hosting.WebApp.Start<Startup>("http://localhost:1001"); How can I isolate both apps so that attribute routing don't conflict? 回答1: Based on your last comment, an example below to

ASP.NET Web API multiple RoutePrefix

为君一笑 提交于 2019-12-04 15:59:59
问题 The opensource Attribute Routing allows to have multiple route-prefixes. Why does ASP.NET Web API 2.0 does not allow to have multiple RoutePrefix(). [RoutePrefix("api/v1/{abc}/Entity")] [RoutePrefix("api/v1/{abc}/{xyz?}/Entity")] public class MyApiController : ApiController { [Route("")] public IHttpResult Get() { return Ok("Hello World"); } } 回答1: You can add a route to the action method also overriding the RoutePrefix with a "~" example: [RoutePrefix("api/v1/{abc}/Entity")] public class

How can I use MVC5 attribute-based routes with a dot/period in them?

戏子无情 提交于 2019-12-04 13:36:53
问题 I have basically an out-of-the box MVC 5.2 app, with attribute-based routes enabled (calling routes.MapMvcAttributeRoutes(); from the provided RouteConfig.RegisterRoutes(RouteCollection routes) method). The following is in HomeController: [Route("hello.txt")] [Route("hellotxt-testing")] public ActionResult ShowFile() { return Content("Hello world"); } I can successfully access /hellotxt-testing (proving attribute-based routing is working correctly): But I get a 404 page if I access /hello.txt