Question

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?

Was it helpful?

Solution 2

Hmmmm. So my browser crashed for some unrelated reason, and now that I have restarted it, the above code seems to be working perfectly as expected. I'm completely confused about how server-side code would now be acting differently because of a browser restart (apparently somehow something was cached incorrectly I guess), but it appears that this is now a non-issue.

EDIT: Well, this is actually still an issue -- not sure why it worked before, but it's a bit random. The bottom line seems to be that MVC does not appear to play nicely with the Trace.axd parser in some circumstances that otherwise produce perfectly valid markup. I really don't have a good explanation, but disabling tracing in web.config bypasses the error. For my purposes for now that's good enough, but I'd love to hear a better explanation from someone else...

OTHER TIPS

I do not really understand your problem , may be I am not skilled enough. Anyway I will try ... ;)

If you want to redirect from the root path, why not using the default document from IIS, put it to index.aspx for example and then add in this page a response.redirect to the page you want to redirect to?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow