ASP.NET MVC Routing - Redirect to aspx?
Posted
by bmoeskau
on Stack Overflow
See other posts from Stack Overflow
or by bmoeskau
Published on 2010-03-30T06:47:39Z
Indexed on
2010/03/30
6:53 UTC
Read the original article
Hit count: 927
This seems like it should be easy, but for some reason I'm having no luck. I'm migrating an existing WebForms app to MVC, so I need to keep the root of the site pointing to my existing aspx pages for now and only apply routing to named routes. Here's what I have:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.IgnoreRoute("{resource}.aspx/{*pathInfo}");
RouteTable.Routes.Add(
"Root",
new Route("", new DefaultRouteHandler())
);
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Calendar2", action = "Index", id = "" } // Parameter defaults
);
}
So aspx pages should be ignored, and the default root url should be handled by this handler:
public class DefaultRouteHandler : IRouteHandler
{
public IHttpHandler GetHttpHandler(RequestContext requestContext)
{
return System.Web.Compilation.BuildManager.CreateInstanceFromVirtualPath(
"~/Dashboard/default.aspx", typeof(Page)) as IHttpHandler;
}
}
This seems to work OK, but the resulting YPOD gives me this:
Multiple controls with the same ID '__Page' were found. Trace requires that controls have unique IDs.
which seems to imply that the page is somehow getting rendered twice. If I simply type in the url to my dashboard page directly it works fine (no routing, no error). I have no idea why the handler code would be doing anything differently.
Bottom line -- I'd like to simply redirect the root url path to an aspx of my choosing -- can anyone shed some light?
© Stack Overflow or respective owner