【问题标题】:ASP.net MVC default route to show actual routeASP.net MVC 默认路由显示实际路由
【发布时间】:2013-09-20 20:50:49
【问题描述】:

我有一个 MVC 3 应用,我的默认路由是 app/index,这意味着如果用户点击“http://www.something.com”, 他们确实看到了“http://www.something.com/app/”。

但是,我想始终显示实际路线,这意味着当用户点击 “http://www.something.com”,我希望地址栏中的 url 显示为“http://www.something.com/app/”。我怎样才能做到这一点?

【问题讨论】:

  • 那么您可能应该使用别名而不是路由。 url: "" 是对url: "app/" 的重定向。

标签: asp.net-mvc asp.net-mvc-3 asp.net-mvc-routing


【解决方案1】:

您可以在您的操作中使用重定向,如下所示:

public class HomeController : Controller
{
   public ActionResult Index(){
     return RedirectToAction("Index","App");
     // or you can do a redirect to a URL. like 301.
     return RedirectPermanent("/app");
   }

}

【讨论】:

    猜你喜欢
    • 2010-11-01
    • 2017-07-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-29
    • 1970-01-01
    • 2012-09-12
    相关资源
    最近更新 更多