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
1 answer

Routing: How to allow Path parameters and Query parameters at the same time?

For my ASP.NET Core 6.0 MVC web application, I need both: http://example.com/users/7 and http://example.com/users?userid=7 My current controller looks like this: [HttpGet("users/{userId}")] public IActionResult GetUser(int userId) { ...…
Ingmar
  • 1,525
  • 6
  • 34
  • 51
0
votes
1 answer

Validate Route Parameter by Name across many endpoints

In a .NET 6 MVC app, I have a lot of endpoints attributed similar to: [HttpGet("getCustomerItem/{customerNumber:int}/{itemNumber:int}")] public async Task GetCustomerItem([FromRoute] int customerNumber, [FromRoute] int…
Jonesopolis
  • 25,034
  • 12
  • 68
  • 112
0
votes
1 answer

ASP.NET Core multi attribute routing

In my ASP.NET Core Web API application, I have declared a route with multiple attributes like following [HttpGet] [Route("{tenantId?}/user/getsettings/{id?}")] When I made a request from swagger, the server is returning 404 not…
ony19161
  • 73
  • 8
0
votes
1 answer

Route that automatically gets name from webapi action

I have ApiController that looks like [RoutePrefix("Companies")] public class CompanyController : ApiController { [HttpGet] [Route("GetCompanyProfile")] public GetProfileOutput GetCompanyProfile() { // some code } } Now, if I try to…
0
votes
3 answers

How to override Controller's name in asp.net mvc core?

In my MVC controller, i have two action methods which are rendering View, other 6 Action Methods are either HttpGet or HttpPost. I want to do the below for ActionMethods rendering View it will be "controller/action". But for the GET/POST, i want it…
ispostback
  • 330
  • 2
  • 7
  • 23
0
votes
1 answer

Asp.net core attribute route issue

I have this code: [Route("Users")] public class UserRegistrationController : Controller { [HttpGet("details/{userId}")] public async Task UserDetails(Guid userId) { // ..... } [HttpPost("Save")] …
leo
  • 451
  • 1
  • 3
  • 12
0
votes
1 answer

Lowercasing actions using Attribute Routing in MVC5

I am leveraging attribute routing in an MVC5 application and enjoy being able to declare conventions at the controller class level per the example below. For the actions within a controller, is there an advisable way to enforce lowercase path / url…
Jakkwylde
  • 1,304
  • 9
  • 16
0
votes
0 answers

.Net Core/MVC Mulit-Tenant Attritubute Routing using Areas with duplicate routes between different controllers

I am trying to create one .NET Core MVC app that serves up different content (that i defined as areas) based on the domain. I am using a constraint that will serve up the appropriate area based on the domain: routes.MapRoute( name: "Website1", …
0
votes
1 answer

Attribute Routing ASP Core 3.0

How do I specify routes to the following API endpoint using attribute routing? The product object returned has a few attributes along with a Store and Manufacturer field that contain either null or a Store and Manufacturer object respectively. …
bob
  • 579
  • 1
  • 8
  • 22
0
votes
0 answers

Attribute routing method not invoking

I am having trouble calling a method with a string parameter in asp.net core web api. The method doesn't get called or invoked. ** My Class looks like this ** [Route("api/[controller]")] [ApiController] public class MyClass : ControllerBase { …
Kaptin Koda
  • 51
  • 1
  • 5
0
votes
1 answer

Only one GET method in controller and yet getting "Not supported by Swagger 2.0: Multiple operations with path"

I know there are many questions with the same title but this one is different. I was getting this error on my product controller, so to investigate the problem I created a demo controller in the ASP.NET Web API 2. DemoController.cs namespace…
0
votes
1 answer

Routing Fails Strangely And I Can't Seem To Pinpoint The Problem

I have 3 links on my website that are generated like below using url.action()
0
votes
1 answer

ASP.NET Web Api attribute routing and query string

I've specified my routing like this: [RoutePrefix("users")] public class UsersController : ApiController { [ResponseType(typeof(List))] [Route("")] public IHttpActionResult GetAll() { } [Route("{birthdate}")] …
user2412672
  • 1,459
  • 3
  • 20
  • 36
0
votes
1 answer

How to allow for null parameters in API Attribute Routing?

I have a method which conducts a search based on 3 criteria: Author Title Keywords The API method I have created for this search currently looks like this: [Route("A={author};T={title};K={keywords}")] [ResponseType(typeof(bool))] public…
Rowan Richards
  • 401
  • 8
  • 20
0
votes
0 answers

Web Api Routing : Multiple controller types were found that match the URL

I'm getting,"Multiple controller types were found that match the URL", Error while performing postman operation for the below API Calls. Can someone help me figuring out the attribute mapping for the same. What I think is resolver considering the…