首页 > 解决方案 > Asp.net WebApi (MVC 5) 从客户端检测到潜在危险的 Request.QueryString 值

问题描述

我的发送模型

public class Mymodel{
    [AllowHtml]
    public string Body { get; set; }
    public int ResponderId { get; set; }
    }

从角度客户端发送

  let params = new HttpParams().append('model', JSON.stringify(mymodel));
   return this.http.post(`url`, data, { params: params });

和服务器

 var httpRequest = HttpContext.Current.Request;
 var model = httpRequest.Params["model"]?.ToString();
 if (model == null) return null;
 return JsonConvert.DeserializeObject<Mymodel>(model);

当body属性有html元素时出错

A potentially dangerous Request.QueryString value was detected from the client

当正文具有 html 元素字符串但不起作用时,我使用此代码。

httpRequest.Unvalidated[parameterName]?.ToString();

标签: asp.net-web-apiparametershttprequestquery-string

解决方案


推荐阅读