开发者

How to NOT route files & directories to ASP.NET MVC

Does anyone know how to ensure that files and dir开发者_如何学Goectories that exist do NOT get routed to .NET MVC if they exist in the root directory?

With Zend Framework, this is done in the .htaccess like so:

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

How is this accomplished in 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.


With URL Routing this should happen by default but you can add in your RegisterRoutes method in Global.asax:

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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜