The1nk
The1nk

Reputation: 702

ASP.Net MVC 3 Broken Routing

I had my site working with the following route, but I needed to fork a new version of the site that didn't need the DB parameter. I removed the DB portion, and published to a new IIS virtual directory, and it just loads. It never stops loading.

Here's the route before:

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

And here's after:

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

That's the only thing I changed in Global.asax.cs. In my controllers, I removed the parameter from my methods: public ActionResult Index(string db) became public ActionResult Index().

Everything works great in Cassini (I think it's called, the local hosting when debugging in VS 2012). However, when I deploy to the webserver, it loads infinitely.

Any ideas?

EDIT: Even when my /Home/Index is as follows, it still loads forever:

    [HttpGet]
    public string Index()
    {
        return "Hello, World!";
        //var dc = BuildDC();
        //ViewBag.Title = "Log in";

        //// Check for cookie that stores Booth Number and Vendors
        //if (HttpContext.Request.Cookies["BoothNumber"] != null && HttpContext.Request.Cookies["Vendors"] != null)
        //{
        //    // We have cookie. Resume session, then.
        //    Session["BoothNumber"] = HttpContext.Request.Cookies["BoothNumber"];
        //    Session["Vendors"] = HttpContext.Request.Cookies["Vendors"];

        //    return RedirectToAction("Login", "Show");
        //}
        //else
        //{
        //    // We no have cookie. Let's do setup process, then.
        //    return RedirectToAction("Setup", "Home");
        //}
    }

The important distinction is that if I debug within VS2012, it runs fine. When I deploy, however, it loads forever. I also feel that this isn't simply an IIS question, as when I changed the route -- I broke it. Thanks!

Upvotes: 2

Views: 562

Answers (1)

Haney
Haney

Reputation: 34802

Your route is fine. It is likely the case that your Index method on your HomeController either: does something infinitely, redirects to the same route infinitely, or runs a long-running external call synchronously like a DB select that takes minutes.

Break it down to a base case and have your Index method simply return a View that says "Hello World", then go from there.

Upvotes: 2

Related Questions