views:

176

answers:

2

I've got the following routes:

// Submission/*
routes.MapRoute(
    "Submission",
    "Submission/{form}",
    new { controller = "Submission", action = "Handle", form = "" });

// /<some-page>
routes.MapRoute(
    "Pages",
    "{page}",
    new { controller = "Main", action = "Page", page = "Index" });

The first routes requests exactly as per this question. The second generically routes a bunch of static content pages. For instance localhost/Help, localhost/Contact, etc. all route to the MainController which simply returns the view according to the page name:

public class MainController : Controller
{
    public ActionResult Page()
    {
        var page = (string)RouteData.Values["page"];
        return View(page);
    }
}

The problem is, during testing at least, localhost/ gives a dir listing instead of routing to Main/Index.aspx. The real problem is it fubars my SiteMap menu because the URLs aren't matching what's defined in the Web.sitemap file. localhost/Index does give me the correct view, however.

The curious thing is this works as expected on Mono / XSP.

+1  A: 

If you are testing it using Visual Studio Dev Server than it should work. I have tried it just now.

On IIS neither of "localhost/" and "localhost/Index" should work unless you enabled wildcard mapping

So it works for me. You probably are missing something that is not obvious from the post.

BTW, your action can be improved:

public ActionResult Page(string page)
{
    return View(page);
}

EDIT: Here is my sample project.

Dmytrii Nagirniak
Upvoted for the tip at least. I can't think of anything that I'm missing ... Mono seems to like it just fine. Can you attach your project so I can test locally?
xanadont
Sure. I've updated the answer.
Dmytrii Nagirniak
Hrm ... archive isn't unzipping properly.
xanadont
Ohh, mate sorry. I'll be able to reupload only on Monday (I'm home now and have no any dev tools here). But what I did is:1. Create default MVC app.2. Added MainController as you provided.3. Removed all the routes in Global.asax.cs and replaced them with your ones.4. Tested and it did work.
Dmytrii Nagirniak
A: 

I finally figured it out. There were (potentially) two things going awry. One, the project must have the MVC project type GUID. Check out this for an idea - though the post isn't quite on topic. Two, Visual Studio 2008 requires SP1 for an updated ASP.NET development server; the version of it prior to SP1 doesn't kick off Global.asax w/o a Default.aspx page.

xanadont