关于MVC RouteExistingFiles疑问后续
前两天写了《关于MVC RouteExistingFiles疑问》,本来希望寻求大佬快速解答,奈何无人问津。
只能查看.NET 源代码,可以使用反编译工具(我用IL spy),也可以在线查看微软提供的:https://referencesource.microsoft.com/
MVC的路由会走UrlRoutingModule,代码在 System.Web/Routing/UrlRoutingModule.cs 中
RouteData routeData = RouteCollection.GetRouteData(context);
GetRouteData的源代码:
public RouteData GetRouteData(HttpContextBase httpContext) {
if (httpContext == null) {
throw new ArgumentNullException("httpContext");
}
if (httpContext.Request == null) {
throw new ArgumentException(SR.GetString(SR.RouteTable_ContextMissingRequest), "httpContext");
} // Optimize performance when the route collection is empty. The main improvement is that we avoid taking
// a read lock when the collection is empty. Without this check, the UrlRoutingModule causes a 25%-50%
// regression in HelloWorld RPS due to lock contention. The UrlRoutingModule is now in the root web.config,
// so we need to ensure the module is performant, especially when you are not using routing.
// This check does introduce a slight bug, in that if a writer clears the collection as part of a write
// transaction, a reader may see the collection when it's empty, which the read lock is supposed to prevent.
// We will investigate a better fix in Dev10 Beta2. The Beta1 bug is Dev10 652986.
if (Count == ) {
return null;
} bool isRouteToExistingFile = false;
bool doneRouteCheck = false; // We only want to do the route check once
if (!RouteExistingFiles) {
isRouteToExistingFile = IsRouteToExistingFile(httpContext);
doneRouteCheck = true;
if (isRouteToExistingFile) {
// If we're not routing existing files and the file exists, we stop processing routes
return null;
}
} // Go through all the configured routes and find the first one that returns a match
using (GetReadLock()) {
foreach (RouteBase route in this) {
RouteData routeData = route.GetRouteData(httpContext);
if (routeData != null) {
// If we're not routing existing files on this route and the file exists, we also stop processing routes
if (!route.RouteExistingFiles) {
if (!doneRouteCheck) {
isRouteToExistingFile = IsRouteToExistingFile(httpContext);
doneRouteCheck = true;
}
if (isRouteToExistingFile) {
return null;
}
}
return routeData;
}
}
} return null;
}
说实话,没看出来什么。
好吧,依稀记得可以调试源代码,也是查了一下,配置VS,下载PDB文件,就能调试了。具体设置,微软地址:https://referencesource.microsoft.com/setup.html
有类似需求的同学可以参考这篇文章,能详细点:https://blog.csdn.net/egman/article/details/78281424
然而,不知道什么原因,我用的VS2017怎样都无法进入源代码。
于是一个问题就变成了两个问题。
于是又搜其他办法,发现JB的DotPeek软件可以,官方地址:https://www.jetbrains.com/decompiler/
这里就不详细介绍操作了,可以参考园友博客:https://www.cnblogs.com/herenwei-wayne/p/5595429.html
run起来,终于进入到源码中GetRouteData方法中了
依次请求静态资源地址,进行调试:
①/a.jpg:匹配到默认路由“controller/action/id”,controller是a.jpg
②/Theme/a.jpg:匹配到默认路由“controller/action/id”,controller是Theme,Action是a.jpg
③/Areas/Admin/a.jpg:匹配到默认路由“controller/action/id”...
④/Areas/Admin/Theme/a.jpg:未匹配到任何路由,renturn
之前的理解是,
1.配到到路由,比如输入a/b/1,但未找到对应的控制器等,提示不存在
2.未匹配到路由,比如输入a/b/c/d/e/f,也会提示不存在
但事实上,
1.配到到路由,比如输入a/b/1,但未找到对应的控制器等,提示不存在(程序可以捕获)
2.未匹配到路由,比如输入a/b/c/d/e/f,路由中return,交由IIS处理
所以,如果利用此特性做文件夹的访问控制,一定要设置对应文件夹的路由规则,然后处理。
关于MVC RouteExistingFiles疑问后续的更多相关文章
- 关于MVC RouteExistingFiles疑问
如图,使用ajpg模拟静态资源.使用 routes.RouteExistingFiles = true; 使静态资源也Map Route,匹配不到则显示Not Foud. ①/a.jpg:访问不到 ② ...
- ASP.NET MVC RouteExistingFiles
遇到这样一个问题:项目是 MVC,但也包含 WebForm 的页面,RouteConfig 中设置了这样一个路由: routes.MapRoute( name: "SubjectIndex& ...
- php源码建博客4--实现MVC结构微型框架
主要: 常量优化路径 自动加载类 优化入口文件 安全访问项目目录 --------------文件结构:-------------------------------------- blog├─App ...
- 用户界面编程模式 MVC MVP MVVM
用户界面编程模式 MVC MVP MVVM 程序 = 数据 + 算法 数据:就是待处理的东西 算法:就是代码 涉及到人机交互的程序,不可避免涉及到界面和界面上显示的数据原始方式是界面代码和逻辑代码糅合 ...
- AppClassLoader和WebAppClasssLoader的坑
最近,打算学习一下spring mvc,为后续做一些积累. 搭建spring+mybatis,动态创建mapper,mapper的文件名称和类在一个目录,但是我之前犯个 错误,大小写写错了,结果我用普 ...
- 【EF6学习笔记】(三)排序、过滤查询及分页
本篇原文地址:Sorting, Filtering, and Paging 说明:学习笔记参考原文中的流程,为了增加实际操作性,并能够深入理解,部分地方根据实际情况做了一些调整:并且根据自己的理解做了 ...
- EF6 学习笔记(三):排序、过滤查询及分页
EF6 学习笔记索引目录页: ASP.NET MVC5 及 EF6 学习笔记 - (目录整理) 上篇:EF6 学习笔记(二):操练 CRUD 增删改查 本篇原文地址:Sorting, Filterin ...
- Activiti进行时——企业工作流生命周期贯通 (zhuan)
http://www.jianshu.com/p/e6971e8a8dad ********************************************** 图1:一个典型的审批工作流程 ...
- Java 注解之总结
注解是Spring和Mybatis框架所大量使用的技术,要想掌握框架相关技术,注解是必须要掌握的. 掌握注解的优势: 1.能够读懂别人写的代码,特别是框架相关的代码. 2.本来可能需要很多配置文件,需 ...
随机推荐
- vue中key的作用 v-for里警告 v-if的复用
vue总是会复用页面上已经存在的dom,区别的方法是加上key就可以,还设有v-for时候的警告也是如此key的作用是区别这条跟那条的.<body> <div id="ap ...
- ArcGIS AddIN Sample学习笔记
1.AddInEditorExtension 功能描述:编辑器扩展,实现在编辑要素,对编辑事件的监听,及对新创建的要素的处理 核心代码: void Events_OnStartEditing() { ...
- 转载:MySQL EXPLAIN 命令详解学习
转载自:https://blog.csdn.net/mchdba/article/details/9190771 MySQL EXPLAIN 命令详解 MySQL的EXPLAIN命令用于SQL语句的查 ...
- centOs6.5配置启动ssh
.非root用户则执行su或su - 或su root或su - root切换为root用户 2.查看SSH是否安装(检查是否装了SSH包) 输入命令:rpm -qa | grep ssh 注:若没安 ...
- [转]在centos 6.4下安装opencv 2.3.1
系统环境介绍: centos 6.4 1.安装依赖包 yum install cmake gcc gcc-c++ gtk+-devel gimp-devel gimp-devel-tools gimp ...
- Docker数据卷
1.volume操作命名:docker volume Usage: docker volume COMMAND Manage Docker volumes Options: --he ...
- MacOS High Sierra 引起 VirtualBox Vagrant 同步慢
问题 最近把mac的操作系统升级到了最新版本发现了一个问题,通过共享文件夹的方式 修改的文件,无法立即同步到虚拟机中,大概需要30秒才能同步到共享文件夹. 操作环境如下 虚拟机:Virtualbox ...
- web前端,多语言切换,data-localize,
demo: 链接:https://pan.baidu.com/s/1zhFHTv4P_epbBfpiggVDXg 提取码:aqts 要想有效果,必须发布在服务器上,可以在IIS上测试. 我只用到了中文 ...
- spring BeanFactory VS FactoryBean
一.FactoryBean示例 public class DateStringFactoryBean implements FactoryBean<Object> { private bo ...
- 关于systemctl
systemctl是CentOS7的服务管理工具中主要的工具,它融合之前service和chkconfig的功能于一体. 启动一个服务:systemctl start firewalld.servic ...