Note that there are some explanatory texts on larger screens.

plurals
  1. POASP.NET MVC - MapRoute versus routes.Add (and 404s)
    primarykey
    data
    text
    <p>I'm just getting started with ASP.NET MVC.</p> <p>What is the difference between MapRoute and routes.Add ? Should I just be using MapRoute? Can I map multiple routes? Which "maps" take precedence... those you called first or last?</p> <p>I'd like to be able to do something similiar to the StackOverflow does for users. But I would like the URL to fit this pattern:<br> "User/{domain}/{username}" to be routed to a UserController</p> <p>and for all other requests to do the typical ASP.NET MVC routing. ex:</p> <pre><code> routes.MapRoute( "Default", "{controller}/{action}/{id}", new { controller = "Home", action = "Index", id = "" } ); </code></pre> <p><strong>UPDATE:</strong><br> When using the URL: <a href="http://localhost:3962/User/MYDOMAIN/BTYNDALL" rel="noreferrer">http://localhost:3962/User/MYDOMAIN/BTYNDALL</a><br> I get the error: <em>HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable.</em> </p> <p>Here is the code I'm using:</p> <pre><code>public class MvcApplication : System.Web.HttpApplication { public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapRoute( "User", "User/{domain}/{username}", new { controller = "User", action = "Index" } ); routes.MapRoute( "Default", "{controller}/{action}/{id}", new { controller = "Home", action = "Index", id = "" } ); } protected void Application_Start() { RegisterRoutes(RouteTable.Routes); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload