• 请求的值。从客户端中检测到有潜在危险的 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);
  • 相关阅读:
    常用网络操作命令
    C语言中的位域[转]
    状态机——一种强大的思想利器
    9030PCI CAN驱动开发点滴
    驱动开发中应该注意的事项
    java 从网络Url中下载文件
    windows pyspider 爬虫安装
    java list去重
    Java 文件分块及合并
    工程部署到linux
  • 原文地址:https://www.cnblogs.com/wybshyy/p/13783795.html
Copyright © 2020-2023  润新知