调试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 @ 2013-03-18 15:55  NewSea  阅读(3679)  评论(0编辑  收藏  举报