关于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.本来可能需要很多配置文件,需 ...
随机推荐
- jquery easyui教程[申明:来源于网络]
jquery easyui教程[申明:来源于网络] 地址:http://wenku.baidu.com/view/570e4d4533687e21af45a941.html
- 实际体验Span<T> 的惊人表现
前言 最近做了一个过滤代码块功能的接口.就是获取一些博客文章做文本处理,然后这些博客文章的代码块太多了,很多重复的代码关键词如果被拿过来处理,那么会对文本的特征表示已经特征选择会有很大的影响.所以需要 ...
- Luogu 1098 - 字符串的展开 - [字符串操作][模拟]
题目链接:https://www.luogu.org/problemnew/show/P1098 题目描述在初赛普及组的“阅读程序写结果”的问题中,我们曾给出一个字符串展开的例子:如果在输入的字符串中 ...
- mysql 用户及权限
永远不要给任何人(除了MySQL root帐户)访问 数据库中的 user表mysql!这很关键. mysql.user表存放所有用户的主机,用户名,密码,权限.直接修改表中信息,需flush pri ...
- 作业2:git使用
作业要求来自于:https://edu.cnblogs.com/campus/gzcc/GZCC-16SE2/homework/2097 远端库地址:https://github.com/yellow ...
- 20165317Java实验五 网络编程与安全
实验五 网络编程与安全 一.中缀转后缀 参考http://www.cnblogs.com/rocedu/p/6766748.html#SECDSA 结对实现中缀表达式转后缀表达式的功能 MyBC.ja ...
- 解决adb:error: unknown host service
1.在使用adb命令跑程序时出现adb: error: failed to get feature set: unknown host service 输入adb shell 时提示error: un ...
- U盘出现很多.exe的文件处理方案
1.原来优盘显示隐藏系统文件后,会有MyDocument文件夹和MyDocument.exe文件两个. 2.在MyDocument文件夹下新建文件夹名为“安全区”的空文件夹. 3.在U盘的根目录下新建 ...
- group_concat的使用
1.场景 仓库使用系统实现了先进先出,给仓库的备货单原先设计如下模式: tx3表: 不同的批次分开行显示,仓库从这个备货单可以知道这个货品需要备货哪些批次,多少数量 用了几天,仓库对此备货单样式提出如 ...
- Centos7下安装Docker(详细的新手装逼教程)
早就听说过Docker,一直不清楚是个啥,今天捣鼓了一下,这里做个记录. --------------------------------------------------------------- ...