zoukankan      html  css  js  c++  java
  • 请求的值。从客户端中检测到有潜在危险的 Request.Form 值

    旧方法:
     
    wef.config里加上节点
    <httpRuntime requestValidationMode="2.0" />

    下面可选
     validateRequest="false"
     
    新方法:
     

    一:前端对富文本字符串进行encodeURI编码,服务端进行HttpUtility.UrlDecode解码操作

    前端:

    var str = '<p><span style="color: #00B0F0;"><em><strong>我想留在你的身边,</strong></em></span><br/></p><p><span style="color: #7030A0;"><strong><span style="text-decoration: underline;">深情款款多么可怜;</span></strong></span></p>';
        $(function() {
            $.ajax({
                type: "post",
                url: "TestHandle.ashx",
                data: { Title: 'jack', Content: encodeURI(str) },
                success: function (data) {
                    $("#div").html(data);
                }
            });
        });

    后端:

    public void ProcessRequest(HttpContext context)
        {
            string str = context.Request["content"];
            string content = HttpUtility.UrlDecode(str);
            context.Response.ContentType = "text/plain";
            context.Response.Write(content);
        }

    二:前端不以form的方式提交,直接以json方式提交,服务端从request的body中读取数据,然后反序列化,得到信息

    前端:

    var str = '<p><span style="color: #00B0F0;"><em><strong>我想留在你的身边,</strong></em></span><br/></p><p><span style="color: #7030A0;"><strong><span style="text-decoration: underline;">深情款款多么可怜;</span></strong></span></p>';
        var temp = { Title: 'jack', Content: str };
        $.ajax({
            type: "post",
            url: "TestHandle.ashx",
            contentType:"application/json;charset=utf-8",
            data: JSON.stringify(temp),
            success: function (data) {
                $("#div").html(data);
            }
        });

    后端:

    string bodyText;
        using (var bodyReader = new System.IO.StreamReader(context.Request.InputStream))
        {
            bodyText = bodyReader.ReadToEnd();
        }
        dynamic bodyObj = JsonConvert.DeserializeObject(bodyText);
    
        context.Response.ContentType = "text/plain";
        context.Response.Write(bodyObj.Content);
  • 相关阅读:
    FastDFS介绍
    SwiftUI 中使用SDWebImageSwiftUI加载网络图片
    SwiftUI 中使用BBSwiftUIKit开源库实现上拉加载和下拉刷新
    SwiftUI 中使用ScrollView+LazyVStack代替List
    SwiftUI 动画
    SwiftUI 中实现省市区选择器
    SwiftUI 中Slider的使用
    SwiftUI 中Stepper的使用
    SwiftUI 中通过Toggle实现单选框和复选框效果
    SwiftUI 中加载bundle中的图片
  • 原文地址:https://www.cnblogs.com/wybshyy/p/13783795.html
Copyright © 2011-2022 走看看