attributerouting

Multiple GET verb on single route with different parameter name Web Api

我怕爱的太早我们不能终老 提交于 2020-01-06 08:04:28
问题 How can possible to call different-different action on basis of parameter name using single route. I need following /api/v1/user GET key=dfddg&secret=fafassaf&query=select id from user where user like '%ggg%' and /api/v1/user GET key=dfddg&secret=fafassaf&ids=fadfdafdsf,faffasfasfsf,asfasfasfasfas,asfasfasfasf I have written following code [RoutePrefix("api/v1/user")] public class UserController : ApiController { [GET("")] public String GetAllUsers(String key, String secret, String query) {

MVC Route Attribute error on two different routes

泪湿孤枕 提交于 2020-01-05 03:10:29
问题 I'm getting an attribute routing error with MVC 5.2. The error is Multiple controller types were found that match the URL. This can happen if attribute routes on multiple controllers match the requested URL. The routes in question are [Route("{classname}/{id:int}")] [Route("Edit/{id:int}")] The url /Edit/123 throws the error, while the url /someword/123 does not throw the error Given that Edit/123 is more specific than someword/123 why would it throw an error on /Edit/123? Thanks, john 回答1:

Route parameter with slash “/” in URL

时光毁灭记忆、已成空白 提交于 2019-12-28 05:56:09
问题 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")] Update: I know there are few options to solve the issue by refactoring the code so please do not offer a solution something like: change the route template to [Route("orders/customers/{orderdate

AttributeRouting - Method to get routes in assembly

喜你入骨 提交于 2019-12-24 04:42:09
问题 I want to use AttributeRouting with Orchard CMS. To do so I need to implement an IRouteProvider with a method that returns an list of Orchard RouteDescriptor s. I need a way to get the routes list so I can do something like this: public IEnumerable<RouteDescriptor> GetRoutes() { return _routes ?? (_routes = MvcRouting.GetRoutes(GetType().Assembly).Select(route => new RouteDescriptor { ... }).ToArray()); } This method is from MvcRouting but I want to use the more feature rich AttributeRouting

Multiple optional parameters web api attribute routing

☆樱花仙子☆ 提交于 2019-12-23 15:24:08
问题 Hi guys i am new to attribute routing and not sure if this is even possible. What i have is an attribute route which works fine like this [HttpGet] [Route("GetIssuesByFlag/{flag:int=3}")] public IEnumerable<IssueDto> GetIssuesByFlag(int flag) now however i want to add some extra optional parameters to narrow down my search so i want to add 2 extra optional parameters. what i have tried: [HttpGet] [Route("GetIssuesByFlag/{flag:int=3?}/{categoryId:int?}/{tagIds?}")] public IEnumerable<IssueDto>

ASP MVC 5 Attribute routing not registering routes

核能气质少年 提交于 2019-12-23 12:31:04
问题 Overview I'm currently trying to get attribute routing to work with my api controllers. It doesn't appear to be working, and I'm unsure why. I'm not sure if I'm missing a crucial step, or what the problem could be. Problem I'm trying to hit localhost/api/user/custom?test=1 but I get a 404 (I expect this to work) If I hit localhost/api/customapi?test=1 I successfully get into my method Why does the first url not work? Setup My setup is as follows: CustomController.cs [System.Web.Mvc

Is it possible to change order of routes in routing table when using attribute routing?

限于喜欢 提交于 2019-12-23 06:59:04
问题 So, I'm switching an area over from using AreaRegistration to using Attribute Routing. I'm running into an issue which appears to be caused by the order in which routes are loaded into the routing table. I'd solved the issue in AreaRegistration by loading in the problematic route last, so that only if all other routes didn't match would that route be matched. With Attribute Routing, this doesn't appear to be possible. I have the Order parameter when creating a route, but this doesn't affect

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

梦想的初衷 提交于 2019-12-23 01:25:26
问题 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;

How to redirect to route using custom attribute routing in MVC5

▼魔方 西西 提交于 2019-12-22 04:46:08
问题 I'm not sure if what I'm attempting to do is valid as I'm a relative newbie to the C# / ASP.NET / MVC stack. I have a controller action like this in ModelController.cs //Get [Route("{vehiclemake}/models", Name = "NiceUrlForVehicleMakeLookup")] public async Task<ActionResult> Index(string vehicleMake) { // Code removed for readaility models = await db.VehicleModels.Where(make => make.VehicleMake.Make == vehicleMake).ToListAsync(); return View(models); } and in another controller called

Using WebAPI in LINQPad?

独自空忆成欢 提交于 2019-12-20 09:24:05
问题 When I tried to use the Selfhosted WebAPI in LINQPad, I just kept getting the same error that a controller for the class didn't exist. Do I have to create separate assemblies for the WebAPI (Controllers/Classes) and then reference them in my query? Here's the code I'm using #region namespaces using AttributeRouting; using AttributeRouting.Web.Http; using AttributeRouting.Web.Http.SelfHost; using System.Web.Http.SelfHost; using System.Web.Http.Routing; using System.Web.Http; #endregion public