Questions tagged [attributerouting]

Define your routes using attributes on action methods in ASP.NET MVC and Web API.

NOTE: Attribute Routing support is currently built into Web API. You can read more information about it here: http://www.asp.net/web-api/overview/web-api-routing-and-actions/attribute-routing-in-web-api-2

371 questions
0
votes
3 answers

ASP.NET Web API Attribute Routing To Wrong Action

I have applied attribute routing on my controller and it'srouting to wrong action. I don't know where I am getting it wrong. Here is my controller: using System.Collections.Generic; using System.Web.Http; using System.Web.Http.Description; using…
0
votes
1 answer

404 Attribute Routing in Area

I am receiving an IIS 404 error message when I try to go to the index method in my home controller in the agency area. If I update the route attribute to: [Route("{action}")] it works fine, but I want to keep index as the default route. In my view…
Andrew
  • 2,013
  • 1
  • 23
  • 38
0
votes
1 answer

How to create a response wrapper for Attribute routing?

When using convention based routing I am able to use a DelegatingHandler to create a response wrapper by overriding the SendAsync method. DelegatingHandler[] handler = new DelegatingHandler[] { new ResponseWrapper() }; …
Zoop
  • 872
  • 3
  • 11
  • 24
0
votes
1 answer

WebAPI: What is the advantage of using Route attribute keyword

see the code first and it is taken from this area https://www.codeproject.com/Articles/1005485/RESTful-Day-sharp-Security-in-Web-APIs-Basic#_Toc423441907 [GET("productid/{id?}")] [GET("particularproduct/{id?}")] [GET("myproduct/{id:range(1,…
Monojit Sarkar
  • 2,353
  • 8
  • 43
  • 94
0
votes
1 answer

The current request for action 'AdminManagement' on controller type 'AdminController' is ambiguous between the following action methods

[Route("admins")] public ActionResult AdminManagement() { EmployeeBuslayer lstEmp = new EmployeeBuslayer(); AdminManamegemtModel comModel = new AdminManamegemtModel(); comModel = lstEmp.GetAdminsWithRole; return…
Nik
  • 73
  • 13
0
votes
0 answers

WebApi Route fails if streamcontentis not empty

I'm trying to send an object using Web-APi 2 and protobuf-net. I keep getting a 404 error so I assume something goes wrong with the routing? When I comment out the serialize line ProtoBuf.Serializer.Serialize(memstream, package); (so the memory…
klennepette
  • 3,176
  • 22
  • 23
0
votes
1 answer

IIS trying to browse directory for an empty route attribute

I have created an api controller with attribute routing: [RoutePrefix("fonts")] public class InfoController : ApiController { [Route("")] [HttpGet] public IHttpActionResult GetSomeInfo() { return Ok(new { Name = "Some name"…
Hossein Margani
  • 1,056
  • 2
  • 15
  • 35
0
votes
0 answers

Attribute routing to controller action isn't working in ASP.NET Core

I've set breakpoints, and followed the flow. The controller is being instantiated, and the parameters are being validated (I have some Data Annotations set up), but the controller method itself isn't being invoked. I think the problem is routing,…
rianjs
  • 7,767
  • 5
  • 24
  • 40
0
votes
1 answer

Wep Api - 405 Method Not Allowed

I have a Web Api project with a controller that has methods for GET, DELETE, POST, and PUT. When I try to do a POST or PUT to this controller I always get a 405 Method Not Allowed error. The data being sent over looks valid, it's just an object with…
DesertFoxAZ
  • 439
  • 1
  • 4
  • 14
0
votes
2 answers

Attribute Routing with Constraint

If I have an ActionResult method like so: public ActionResult AllSummaries(int? page, DateTime? yesterday) Instead of the route being like: http://serverName/projectName/controllerName/AllSummaries?yesterday=04/03/2017 I would like it to…
Grizzly
  • 5,873
  • 8
  • 56
  • 109
0
votes
1 answer

Create URL in Razor View for Attribute Route containing parameters

I have the controller below with a route specified which contains a parameters matching the overload on the action. public class OrganisationsController : Controller { [HttpGet] [Route("organisations/{id}/employees")] public ActionResult…
0
votes
1 answer

Attribute routing not hitting the action methods inside controllers

I'm using attribute routing in my MVC5 application and it is working fine. When I tried to create an area and placed attribute routing on the controller inside it, it returns 404. I know, to enable attribute routing inside Area, I have to use…
0
votes
1 answer

MVC 5 Attribute Routing: Removing Unnecessary Route Attribute From Controller Actions

I have a requirement where the resources on the home controller should be accessed without the need to enter the name of the controller in the URL. For instance, index action should be loaded when I navigate to mysite.com/ and contact page should be…
0
votes
1 answer

From route configuration to attribute routing

I have the following route configured in my ASP.NET Web API 2 Project: config.Routes.MapHttpRoute( name: "1MandatoryStringParameter", routeTemplate: "api/{controller}/{data}", defaults: null, …
anon
0
votes
0 answers

Change route to username after registration

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…