调试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 ;
  }
}
复制代码

 

即可。

 

 

 
 

 

 

posted @   NewSea  阅读(3682)  评论(0编辑  收藏  举报
编辑推荐:
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
阅读排行:
· 周边上新:园子的第一款马克杯温暖上架
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· Ollama——大语言模型本地部署的极速利器
· DeepSeek如何颠覆传统软件测试?测试工程师会被淘汰吗?
· 使用C#创建一个MCP客户端
点击右上角即可分享
微信分享提示