代码之家  ›  专栏  ›  技术社区  ›  doremi

如何不将文件和目录路由到ASP.NET MVC

  •  1
  • doremi  · 技术社区  · 14 年前

    有人知道如何确保存在的文件和目录在根目录中时不会被路由到.NETMVC吗?

    RewriteCond %{REQUEST_FILENAME} -s [OR]
    RewriteCond %{REQUEST_FILENAME} -l [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    

    如何在IIS中实现这一点?

    如果myDir存在于web\u根目录中,并且用户访问domain.com/myDir,则myDir不会路由到MVC,而是将用户发送到该目录。

    1 回复  |  直到 14 年前
        1
  •  1
  •   Markive    14 年前

    对于URL路由,这在默认情况下应该发生,但您可以在Global.asax中添加RegisterRoutes方法:

    Sub RegisterRoutes(ByVal Routes As RouteCollection)
    
    Routes.RouteExistingFiles = False
    

    这些也可能有助于:

        ' Ignore Routes
        Dim Ir As Route = New Route("{resource}.axd/{*pathInfo}", New StopRoutingHandler())
        Routes.Add(Ir)
    
        Dim ignore1 As Route = New Route(("favicon.ico"), New StopRoutingHandler())
        Routes.Add(ignore1)
    
        Dim ignore2 As Route = New Route(("Telerik.RadUploadProgressHandler.ashx/{*pathInfo}"), New StopRoutingHandler())
        Routes.Add(ignore2)
    
    End Sub