mvc从响应重定向中删除url页面名称

时间:2018-04-04 19:49:00

标签: asp.net-mvc url

我已经阅读了很多帖子,告诉我们如何从网址中删除Controller Action

我的情况最简单,但不要这样做。

启动时,默认执行Home控制器。根据Active Directory条件,我必须重定向到某些标准HTML。它可能是

Response.Redirect("Page1.html");
Response.Redirect("Page2.html");
Response.Redirect("Page3.html");

会显示

 Localhost:4000/Page1.html or
 Localhost:4000/Page2.html or
 Localhost:4000/Page3.html

我需要的只是显示

  

本地主机:4000

感谢

1 个答案:

答案 0 :(得分:1)

你可能想要写一个像这样的具体行动

所以首先让我们说你的路由配置是完整的,然后使用默认路由,然后在家庭控制器中改变它的索引,如

   public ActionResult Index()
    {
       if(Your condition)
    {
      return new FilePathResult($"~/Views/Page1.html.html", "text/html");
    }  
      if(Your condition2)
    {
      return new FilePathResult($"~/Views/Page2.html", "text/html");
    }  
        if(Your condition3)
    {
      return new FilePathResult($"~/Views/Page3.html", "text/html");
    }    
}