In a brand new ASP.NET MVC2 project, I want the user to be redirected to
在全新的ASP中。NET MVC2项目,我希望用户重定向到。
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.
如何做到这一点,使http://
1 个解决方案
#1
2
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();
}
}
}
#1
2
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();
}
}
}