asp.net-mvc-routing

ASp.Net MVC Default Route

I have my default route defined like this routes.MapRoute( "Default", // Route name "{controller}/{action}/{id}", // URL with parameters new { controller = "Home", action = "Index", id = "" } // Parameter defaults ...

ASP.NET routing with optional URL segments

I'm working on an ASP.NET MVC task list and I'd like to get fancy with the URL routing when filtering the list. I have an action method defined like this: public ActionResult List(int categoryID, bool showCompleted, TaskFilter filter); enum TaskFilter { MyTasks, MyDepartmentTasks, AllTasks } I want my URLs to look like this: /Tasks/...

MVC on IIS6 - 'Home' links not working correctly

I'm deploying a MCV 1.0 project on a web server running IIS6. (not by my choice) I've thru Steve Sandersons article Here and Phil Haack's article but I'm still having probelms. Right now I'm trying to implement Option 2 from Steve Sandersons article. The main problem I'm having is with the Home link not rendering correctly. For Instanc...

ASP.NET-MVC . How to get the controller name from an url?

How can I get the controller name of a relative Url, using the routes I have defined in Global.asax? Example: if I have a route defiend like this: routes.MapRoute( "Default", // Route name "{language}/{controller}/{action}/{id}", // URL with ...

Advanced Routing Behaviour with ASP.NET MVC Routing

Given a url that follows the following pattern: firstcolor={value1}/secondcolor={value2} where value1 and value2 can vary and an action method like: ProcessColors(string color1, string color2) in say a controller called ColorController. I want the following route evaluation: URL '/firstcolor=red' results in a call like ProcessColor...

ASP.NET MVC 2 How are urls/routes, views related to controllers?

Could someone explain how routes are associated with controllers in MVC 2? Currently, I have a controller in /Controllers/HomeController.cs and a view /Home/Index.aspx. My route registration method looks like this: public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*path...

ASP.NET MVC 2 and custom httpModule precedence

I have a custom HttpModule rewrite engine in an existing web application project that maps urls of the form /tom/dick/harry/.../.../... to a hierarchical navigation system stored in a database, ultimately resulting in a HttpContext.Current.RewritePath() call to the .aspx page that the requested path resolves to. I'm interested in mixi...

ASP.NET MVC form that redirects to a route

Hello is it possible to have an ASP.NET MVC form that uses the routes defined in Global.asax to post its values (via a GET request)? I have the form defined like this: <% using (Html.BeginForm("CanviaOpcions","Sat",FormMethod.Get)) { %> <fieldset> <legend>Opciones</legend> <%= Html.DropDownList("nomSat")%> ...

Routelink viewdata value is always null

I have a routing rule routes.MapRoute( "Search", // Route name "Restaurant/AdvancedSearch/{foodType}", // URL with parameters new { controller = "Restaurant", action = "AdvancedSearch", foodType = "" } // Parameter defaults ...

Asp.Net MVC Routing - how do I match the whole URL?

I'm trying to create a catch-all route to track when an affiliate string is in the URL. An affilite code is marked by an x followed by an int, and will only appear at the end of a URL (but before the query string). The idea is that I will extract the affiliate ID, do some logging, then do a 301 to the same request without the affiliate ...

mvc routes to share the same action??

I have the following two routes defined in my MVC app.;- At the moment I have two "MVC View content pages" defined /ShowName/NameById /ShowName/Index However the content on these two pages are identical? Is it possible for two routes to share the same content page? If not then can I a) create a single rule for both routes or b) should...

Routing and GetVirtualPath problem

I'm using MVC 2 Preview2, with two areas in a single project. When I use RouteTable.Routes.GetVirtualPath(this.viewContext.RequestContext, null) from inside an area, I got the virtual path to the first area instead. Except for this, areas are working pretty well. What can I doing wrong? ...

MVC 2 AreaRegistration Routes Order

I noticed that in MVC 2 Preview 2, AreaRegistration is loading the routes for each area in an arbitrary order. Is there a good way to get one before the other? For example, I have two areas - "Site" and "Admin". Both have a "Blog" controller. I would like the following: /admin/ --> go to Admin's Blog controller / --> go to Site...

Proper approach to generating URL's with a catchall

Url.Action is a great mechanism to generate URL's as you can think in terms of controllers, actions, and parameters instead of hard-coded URL's. However it's not going to work when you use a catchall parameter in your route. What would be a recommended approach to generate URL's for a route that is using a catchall? ...

ASP.Net MVC - Trapping certain URL's to do 301 Redirect

I am moving from an old site design to a new design with new URL's. All previous page names were static files called PageXX.html, PageX.html, Index.html - where X is a number. My site is now dynamic but I want to trap for those 3 incoming url's and then try and redirect to a certain new page (301 Redirect) else send them to the home pa...

301 Redirection Layer in Microsoft asp.net MVC using phil haacked code doesn't work for me

I need a set up a website that accepts URLs from an older web site version and permenantly redirect them to the new site. I tried this code from Phil Haack's blog but it seems to redirect everything and severely screw up all route generations. http://haacked.com/archive/2008/12/15/redirect-routes-and-other-fun-with-routing-and-lambdas....

ASP.NET MVC - Shortening urls

I am developing an international web site - multiple countries, multiple languages. I am trying to create SEO friendly URLs. For example the catalog consists of cartesian product Regions x Categories. A typical catalog url has 7 levels of hierarchy: www.site.com/en/Catalog/Browse/10/28/London/Category1 The route format is as follows: ...

Force a complete match on all tokens of a MapRoute against URL string

Is there any way to force a Route to be executed, only if all tokens are present in the URL string? Consider this Route: RouteTable.Routes.MapRoute( "Default", "{controller}/{action}/{id}", new { controller = "Test", action = "Index", id = 0 } ); This Route execute on /Home/Index/1 and /Hom...

asp.net MVC and RESTful routing, rails-style. Is it possible?

Is there any way to get truly restful routing working in MVC, just like the rails dudes have? I 'm talking about nested urls like /bands/metallica/albums/killemall/track/4 The only library that I found to be useful is Steve Hodgkiss' Restful routing. It seems though a bit risky to base my whole project's routing on this guy's pet-projec...

Returning a view with it's model from an ActionFilterAttribute

When implementing error-handling using the built-in validation-helpers on a strongly-typed view, you usually create a try/catch block within the controller and return a view with it's corresponding model as a parameter to the View() method: The controller public class MessageController : Controller { [AcceptVerbs(HttpVerbs.Post)] ...