asp.net-mvc-routing

ASP.NET MVC Dynamic Routes and Action Links with Arbitrary Depth

I'd like to put together a forum/message board with ASP.NET MVC. Pretty common on these types of forums are hierarchical board categories, so for instance: -General Discussion -Technical Support --Website Technical support --Product Technical Support ---Product A Technical Support ---Product B Technical Support Below each category are...

Why is ASP.NET MVC ignoring my trailing slash?

Consider the following route: routes.MapRoute( "Service", // Route name "service/", // URL with parameters new {controller = "CustomerService", action = "Index"} // Parameter defaults ); Using Url.Action("Service", "CustomerService") produces an url of /service instead of the expected /service/ Is ...

ASP.NET MVC ambiguous action methods

I have two action methods that are conflicting. Basically, I want to be able to get to the same view using two different routes, either by an item's ID or by the item's name and its parent's (items can have the same name across different parents). A search term can be used to filter the list. For example... Items/{action}/ParentName/...

How can I generate ASP.NET MVC URLs inside a unit test project?

How can I generate the URLs corresponding to the controller, action, and parameters (for a given ASP.NET MVC project) in another project (a class library used for testing)? All I have found so far is HtmlHelper.GenerateRouteLink, but didn't find yet how to pass the correct request context and route collection. ...

ASP.NET MVC Routing Root Level Views

I thought this would be fairly easy, but I'm totally baffled. I want one controller's views to be at the root level of the application, rather than in a subdirectory for that controller, but I cannot figure it out. I'd like to have these two urls: /Info - This should action "Info" on controller "Home" /Admin/ - This should be action...

Mixed Asp / Asp.NET / ASP.NET MVC Site

I am trying to set up so that my default page http://demo.liginsurance.com/ goes to http://demo.liginsurance.com/default.asp currently it goes to http://demo.liginsurance.com/Home/Index what route can i write or ignore to get that to work... -Thanks Hurricane ...

Custom Routing Rules (e.g. www.app.com/project/35/search/89/edit/89)

I would like to create routing rules like the following: www.app.com/project/35/search/89/edit/48 ---> action is edit in the project controller The passed variables should be project# (35), search# (89), and edit#(48) Can someone help me structure a routes.MapRout() for this. I want to use: routes.MapRoute( "Default", ...

How to access HTML files from ASP.NET MVC VIEWS Folder

Hi All, I will like add conventional HTML page under VIEWS folder (in ASp.NET MVC) page. I have added the route exceptions as mentioned below. routes.IgnoreRoute("{resource}.htm/{*pathInfo}") routes.IgnoreRoute("{resource}.html/{*pathInfo}") Although it does work when I put the html files out of VIEWS folder but I get Page ...

Different websites on different domains, one .NET MVC application?

Hi, Is it possible to have one .NET MVC application, and have it accessible from different domains, in such a way that the content will be domain-dependant? For example, both www(dot)site1(dot)com and www(dot)site2(dot)com will point to my server's IP, and to the same website in IIS. In that website my .NET MVC application will reside....

ASP.net MVC custom route handler/constraint

I need to implement an MVC site with urls per below: category1/product/1/wiki category1/product/2/wiki category1/sub-category2/product/3/wiki category1/sub-category2/sub-category3/product/4/wiki etc. etc. where the matching criteria is that the url ends with "wiki". Unfortunately the below catch-all works only in the last part of th...

How to handle empty URL in ASP.NET MVC

How do you set up the routing to handle http://mysite.com/Foo? Where foo can be any value. I want it to go to /Home/Action/Id where foo is the id. These are the mappings I have tried: routes.MapRoute("Catchall", "{*catchall}", new { controller = "Home", action = "Index", id=""}); routes.MapRoute("ByKey", ...

Adding Redundant Information to a MVC Route

As you come to this question you'll notice the title of the question is in the address bar and the link you clicked on to get here. I am not sure the exact terminology so found it difficult to search for but how can I do something similar? That is, How can I add data to the address bar which is purely for show/search engines. Thanks ...

How to prevent Url.RouteUrl(...) from inheriting route values from the current request

Note: I'm answering my own question immediately below Lets say you have an action method to display products in a shopping cart // ProductsController.cs public ActionMethod Index(string gender) { // get all products for the gender } Elsewhere, in a masthead that is displayed on every page you are using Url.RouteUrl to creat...

How to change an ASP.net MVC URL

Is there a simple way of generating a new Route-URL without all this faff. I'm currently Handling several routes to the same view, all of which end with /{pagenumber} All I'm trying to do is delete everything back to the last backslash and replace the number. I was trying to avoid using the URL Maker as it seems a tad overkill for pa...

Form is posting to wrong URL

Original title: Can't fixed misconfigured routes I want to make a search based in a filter (with 4 possibles values) and a criteria entered by the user. I have the following routes: routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapRoute( "SubLineasProductosDefault", "SubLineas...

ASP.NET MVC Routing Questions

I just started using ASP.NET MVC and I have two routing questions. How do I set up the following routes in ASP.NET MVC? domain.com/about-us/ domain.com/contact-us/ domain.com/staff-bios/ I don't want to have a controller specified in the actual url in order to keep the urls shorter. If the urls looked liked this: domain.com/comp...

ASP.NET MVC routing - trying to have a name in the url

hi all, I have currently the following routes: routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.IgnoreRoute("{resource}.gif/{*pathInfo}"); MvcRoute.MappUrl("{controller}/{action}/{ID}") .WithDefaults(new { controller = "home", action = "index", ID = 0 }) .WithConstraints(new { controller...

Can I map new routes to the RouteCollection outside Global.asax?

I'd like to occasionally map new routes to the RouteCollection during program execution long after the Global.asax RegisterRoutes() method had first executed. How can I do this? ...

ViewContext.RouteData.Values["action"] is null on server... works fine on local machine

I'm having a weird issue where ViewContext.RouteData.Values["action"] is null on my staging server, but works fine on my dev machine (asp.net development server). The code is simple: public string CheckActiveClass(string actionName) { string text = ""; if (ViewContext.RouteData.Values["action"].ToString() == actionN...

Setting Routes Inside/Near Controller Actions?

About 10 stackoverflow.com podcasts back Jeff mentioned that instead of wiring up his routes inside of the global.asax file he instead put them inside his controllers near the actions those routes would invoke. How does one go about doing this? Doesn't a route have to be registered before the controller it routes to is hit? Does he ...