简体   繁体   English

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

[英]How to NOT route files & directories to ASP.NET MVC

Does anyone know how to ensure that files and directories that exist do NOT get routed to .NET MVC if they exist in the root directory? 有谁知道如何确保存在于根目录中的文件和目录不会被路由到.NET MVC?

With Zend Framework, this is done in the .htaccess like so: 使用Zend Framework,这可以在.htaccess中完成,如下所示:

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

How is this accomplished in IIS? 如何在IIS中完成?

Here's a use case: If myDir exists in the web_root and the user visits domain.com/myDir, myDir is not routed to MVC, but rather the user is sent to that directory. 这是一个用例:如果web_root中存在myDir,并且用户访问domain.com/myDir,则myDir不会路由到MVC,而是会将用户发送到该目录。

With URL Routing this should happen by default but you can add in your RegisterRoutes method in Global.asax: 使用URL路由默认情况下会发生这种情况,但是您可以在Global.asax中添加RegisterRoutes方法:

Sub RegisterRoutes(ByVal Routes As RouteCollection)

Routes.RouteExistingFiles = False

These may also help: 这些可能也有帮助:

    ' 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM