• 调试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 ;
      }
    }

    即可。

     
     
    alarm   作者:NewSea     出处:http://newsea.cnblogs.com/    QQ,MSN:iamnewsea@hotmail.com

      如无特别标记说明,均为NewSea原创,版权私有,翻载必纠。欢迎交流,转载,但要在页面明显位置给出原文连接。谢谢。
  • 相关阅读:
    在EasyDarwin进行实时视频转发的两种模式
    Windows服务中读取配置文件的方法
    reactor设计模式
    用Darwin实现流媒体转发程序(附源码)
    Windows服务中读取配置文件的方法
    c# 参数 this
    基于DSS的先侦听后推送式流媒体转发
    用live555做本地视频采集转发,附源码
    Darwin在转发流过程中对推送端断开的处理问题
    基于live555的流媒体代理转发服务器
  • 原文地址:https://www.cnblogs.com/newsea/p/2966173.html
Copyright © 2020-2023  润新知