调试MVC4的方法
我并没有按网上的方法调试成功,所以靠自己解决它。
1. 从官方下载 MVC 4 源码。
2. 按以下顺序,新建项目,不要强名称,如果报错,手动解决,大部分是把 internal 关键字改为 public . 为了速度,可批量替换。
1.System.Web.Razor
2.System.Web.WebPages.Deployment
3.System.Web.WebPages
4.System.Web.Helpers
5.System.Web.WebPages.Razor
最后是
System.Web.Mvc
3. 打开项目 , 去除以上6个官方dll , 引用自己编译的dll 。
4. 在web.config 和 MVC 的各个 web.config 中,把 以上六个 dll 的 PublicKeyToken 设置为 null , 可批量替换 , 并且根web.config 做如下修改
<runtime> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <dependentAssembly> <assemblyIdentity name="System.Web.Helpers" publicKeyToken="null" /> <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.1.0.0" /> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="System.Web.Mvc" publicKeyToken="null" /> <bindingRedirect oldVersion="1.0.0.0-4.0.0.0" newVersion="4.1.0.0" /> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="System.Web.WebPages" publicKeyToken="null" /> <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.1.0.0" /> </dependentAssembly> </assemblyBinding> </runtime>
重新编译,即可调试。
顺便记录一下,网上所说的 MVC3 解决 检测到有潜在危险的Request.Form 值 , 只能解决单个Action . 而我想 全局设置不检测客户端 Post 的值。
使用以上方法, 设置出错中断。 在 DefaultModelBinder . ShouldPerformRequestValidation 方法有如下判断:
private static bool ShouldPerformRequestValidation(ControllerContext controllerContext, ModelBindingContext bindingContext) { if (controllerContext == null || controllerContext.Controller == null || bindingContext == null || bindingContext.ModelMetadata == null) { // To make unit testing easier, if the caller hasn't specified enough contextual information we just default // to always pulling the data from a collection that goes through request validation. return true; } // We should perform request validation only if both the controller and the model ask for it. This is the // default behavior for both. If either the controller (via [ValidateInput(false)]) or the model (via [AllowHtml]) // opts out, we don't validate. return (controllerContext.Controller.ValidateRequest && bindingContext.ModelMetadata.RequestValidationEnabled); }
所以只需在 Controller 的基类进行如下设置:
public class BaseController: Controller { public BaseController() { this.ValidateRequest = false ; } }
即可。
![]() |
作者:NewSea 出处:http://newsea.cnblogs.com/
QQ,MSN:iamnewsea@hotmail.com 如无特别标记说明,均为NewSea原创,版权私有,翻载必纠。欢迎交流,转载,但要在页面明显位置给出原文连接。谢谢。 |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· 周边上新:园子的第一款马克杯温暖上架
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· Ollama——大语言模型本地部署的极速利器
· DeepSeek如何颠覆传统软件测试?测试工程师会被淘汰吗?
· 使用C#创建一个MCP客户端