asp.net-mvc-routing

MVC area route resolution

倖福魔咒の 提交于 2019-12-24 03:23:28
问题 Using MVC3/4 if you have area's in your solution, what is the order that it will try and resolve the areas and root level controllers? For example: Does it first try the root level routes and then the area level routes in alphabetical order? Or does it first check the area level routes in alphabetical order and then the root level? Thanks 回答1: MVC resolvers area specific routes first and then root level routes. This is because by default you have next code in Global.asax: protected void

Is it wrong to use routes versus query string parameters? [closed]

自闭症网瘾萝莉.ら 提交于 2019-12-24 01:47:10
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed last year . I have a Web API controller with two actions. One action returns a list of all entities from the database. The second action takes a query string parameter and filters the entities. The search action is wired up to use the query string parameter. It works but we encountered an

Reference generic url parameter in AuthorizeAttribute

戏子无情 提交于 2019-12-24 01:45:21
问题 If my action has a path like /controller/action/{id} I can get id in an AuthorizeAttribute by doing httpContext.Request.RequestContext.RouteData.Values["id"] . Conversely, if it's something like /controller/action?id={id} I can get it by doing httpContext.Request.QueryString["id"] . I'll need yet another way if it's form data from a POST. Is there a way to say "Get what you would put in the parameter with name 'id', regardless of how the route is specified?" 回答1: var id = Request

Adding company name in Routes mvc 4

拈花ヽ惹草 提交于 2019-12-24 00:22:59
问题 I have been trying to give options to users like Facebook to add their company name in the URL: http://localhost:50753/MyCompany/Login I have tried different URLs, but it didn't work. routes.MapRoute( name: "Default", url: "{companyName}/{controller}/{action}", defaults: new { controller = "Login", action = "Index"} ); routes.MapRoute( name: "Login", url: "{controller}/{action}/{id}", defaults: new { controller = "Login", action = "Index", id = UrlParameter.Optional } ); Now when I add this

How to use the same route with different parameter types?

和自甴很熟 提交于 2019-12-23 12:49:28
问题 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 I needed to setup routes in the

Creating a different route to a specific action mvc 6

南楼画角 提交于 2019-12-23 12:27:58
问题 I am working on an asp.net 5 mvc api, and I am currently working on the Accounts Controller. since I saw in many different places that there is a convention of using /api/Token routing to a login in a web api. I would like to route to that specific method without the accounts prefix, I would prefer not using a different controller, and I would prefer using Attributes over routing in Startup.cs to avoid confusion in the future. this is what I have currently [Route("api/[controller]")] public

ASP.NET MVC : strange POST behavior

你离开我真会死。 提交于 2019-12-23 10:16:20
问题 ASP.NET MVC 2 app I have two actions on my controller (Toons): [GET] List [POST] Add App is running on IIS7 integration mode, so /Toons/List works fine. But when I do POST (that redirects to /Toons/List internally) it redirects (with 302 Object Moved) back to /Toons/Add. The problem goes away if I use .aspx hack (that works in IIS6/IIS7 classic mode). But without .aspx - GET work fine, but POST redirects me onto itself but with GET. What am I missing? I'm hosting with webhost4life.com and

How to make Login page as a default route in ASP .NET Core 2.1?

*爱你&永不变心* 提交于 2019-12-23 09:29:30
问题 I am beginner in ASP .NET Core 2.1 and working on project which is using ASP .NET Core 2.1 with individual authentication. I want to make my login page as my default route instead of Home/Index: routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); Any help how can i change it as ASP .NET Core 2.1 as Login is now used as a razor page instead of MVC Action View. 回答1: Use this in ConfigureServices method. services.AddMvc().AddRazorPagesOptions(options=> {

Strategy for Hierarchical MVC Routing

陌路散爱 提交于 2019-12-23 05:32:31
问题 I am sure this has been answered somewhere else but I cannot seem to find a definitive posting anywhere. Most of the postings regarding hierarchical routing talks about when you want an unlimited number of tokens in the Url. My question deals more with when it does not make sense for a given Entity to exists without being associated in the context of another Entity. For example, I have a Contract entity along with the expected Contract controller. It has the standard Actions like Index, Edit,

Routing issue in application using MVC/Durandal and located in IIS subfolder

余生颓废 提交于 2019-12-23 02:24:21
问题 I´m looking for a solution for my problem I mentioned in the title. First of all you need to know that I have two MVC applications published on an IIS. The first application is kind of a central management system so I set up a Site called "Management" in IIS. The second app is a MVC web shop embedded as application (subfolder) in Site "Management". For the shop I created an MVC application using durandal. Now it seems like I have a routing problem. When I enter the URL defined in Site