views:

219

answers:

2

I'm still new to ASP.NET MVC and I'm struggling a little with the routing.

Using the ASP.NET development server (running directly from Visual Studio), my application can find its views without any problems. The standard ASP.NET URL is used - http://localhost:1871/InterestingLink/Register

However, when I publish my site to IIS and access it via http://localhost/MyFancyApplication/InterestingLink/Register, I get a 404 error.

Any suggestions on what might be wrong?

More info...

This is what my global.asax file looks like (standard):

public class MvcApplication : System.Web.HttpApplication
    {
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
                "Default",                                              // Route name
                "{controller}/{action}/{id}",                           // URL with parameters
                new { controller = "Home", action = "Index", id = "" }  // Parameter defaults
            );

        }

        protected void Application_Start()
        {
            RegisterRoutes(RouteTable.Routes);
        }
    }

My controller is also very simple:

public class InterestingLinkController : Controller
{
    public ActionResult Register()
    {
        return View("Register");
    }
}
+1  A: 

Lots of things could be wrong:

  • Is the IIS Virtual Directory & Application set correctly?
  • Is the ASP.NET application being called at all? (Add some logging/breakpoiont in Application_Start and Application_BeginRequest)

Just for a start. You are going to have to apply the usual debugging approaches.

(To avoid issues like this, I rarely use the development server and just use IIS the whole time: most difficult thing is remembering to run VS elevated every time.)

Richard
+1  A: 

I figured out what was wrong. The problem was actually that IIS5 (in Windows XP) does not fire up ASP.NET when the URL does not contain a .ASPX. The easiest way to get around this is to add a '.aspx' to your controller section in global.asax. For example:

routes.MapRoute(
                "Default",                                              
                "{controller}.aspx/{action}/{id}",                      
                new { controller = "Home", action = "Index", id = "" }  
            );

Not pretty, but it will do.

willem