views:

113

answers:

1

In a brand new ASP.NET MVC2 project, I want the user to be redirected to

http://<mysite>/home/index 

rather than

http://<mysite>/

We do this with our other sites for tracking purposes, to avoid the scenario where hits to the same default page show up as

http://<mysite>/
http://<mysite>/default.aspx

How do I accomplish this so that http://<mysite>/ automatically redirects to whatever default controller/action I have set up in my routing? Please note that I am aware the two are functionally equivalent, as the default controller action will be executed either way. I'm just interested in forcing consistent URLs in the browser.

A: 

Something like this should do it, no?

public class HomeController : Controller
{
    public ActionResult Index()
    {
        string incomingUrl = HttpContext.Request.Url.LocalPath;

        if (incomingUrl == "/")
        {
            return Redirect("/home/index");
        }
        else
        {
            return View();
        }
    }
}
ewwwyn