2017-02-20 104 views
0

我不再exisits /应用MVC 5 URL重写精确匹配只

我想所有请求重定向到该到主页,但在我的网站的虚拟目录仅当其准确的URL /应用程序,我尝试了以下但这也重定向的URL /约会

<rule name="RedirectToRoot" patternSyntax="ECMAScript" stopProcessing="true"> 
    <match url="/app$" /> 
    <action type="Redirect" url="/" redirectType="Permanent"/> 
</rule> 

我知道问题出在正则表达式使用IM即时通讯,但不知道如何解决它

回答

0

使用此

解决它
<rule name="RedirectToRoot" patternSyntax="ECMAScript" stopProcessing="true"> 
    <match url="^app/(.*)" /> 
    <action type="Redirect" url="{R:1}" redirectType="Permanent"/> 
</rule> 
0

您可以使用下面的解决方案从MVC 5.

routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); 
     // Add the below 
        routes.MapMvcAttributeRoutes(); 
// Add the below ^^ 

     routes.MapRoute(
        name: "Default", 
        url: "{controller}/{action}/{id}", 
        defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } 
      ); 

RouteConfig.cs你必须添加routes.MapMvcAttributeRoutes();.一旦这样做你可以标记[路线(“MyDenfinedURL”)上面的操作方法

[Route("MyDenfinedURL")] 
public ActionResult MyAction() 
     { 
      //My do over the method  
      return View(); 
     } 

一旦做到这一点你的工作就结束了。我的源代码链接:http://www.dotnet-stuff.com/tutorials/aspnet-mvc/understanding-url-rewriting-and-url-attribute-routing-in-asp-net-mvc-mvc5-with-examples