且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

MVC 4路由-忽略图像请求

更新时间:2022-11-26 13:54:38

如果要忽略文件夹,可以这样写:

If you want to ignore folder you can write like this:

routes.IgnoreRoute("Images/{*pathInfo}");

如果只想忽略文件夹中的某些文件,可以使用 IgnoreRoute() 像这样:

if you want to ignore only certain files in folder you can use this overload of IgnoreRoute() like this:

routes.IgnoreRoute("{Images}", new { assets = @".*\.(jpeg|gif|jpg)(/.)?" });

如您所见,约束参数可以是像 RegExp 这样实现。

As you can see constraints parameter can be implemented like RegExp.