c# - 从客户端将数据和文件发布到 Web api 中检测到潜在危险的 Request.Form 值
问题描述
我有一个表单,用于将数据和文件发布到web
api
endpoint
. 数据字段之一是RichTextField
使用summernote
插件。
发布到的angularjs
脚本endpoint
如下所示:
$scope.transaction = {};
var files = $scope.myFile;
var fd = new FormData();
angular.forEach(files, function (value, key) {
fd.append("file" + key, value[0]);
});
fd.append("fileContent", JSON.stringify({ fileContent: $scope.transaction }));
dataService.uploadFile(baseAddress + "/Generate", fd)
.success(function (data) {}).error(function (data) { });
接受请求的端点如下所示:
[HttpPost]
public async Task<IHttpActionResult> Generate()
{
try
{
if (!Request.Content.IsMimeMultipartContent())
{
throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
}
var contentResult = System.Web.HttpContext.Current.Request.Form;
var key = contentResult.AllKeys[0];
var val = contentResult.GetValues(key)[0];
此时var val = contentResult.GetValues(key)[0];
我收到此错误消息:
A potentially dangerous Request.Form value was detected from the client
我试过这个:
[System.Web.Http.HttpPost, System.Web.Mvc.ValidateInput(false)]
还
<pages validateRequest="false" />
<httpRuntime requestValidationMode="2.0" />
解决方案
您必须允许 html 标签,因为 Summernote 数据包含它们。为此,您需要将AllowHtmlAttribute添加到您的方法中。
你可能需要做一些修改,因为它可以很容易地做 xss 和其他事情。
推荐阅读
- javascript - JsonResult 只接受第一个参数,忽略其余参数
- c# - 如何使用户输入int null值c#
- ios - 成功添加 cordova-plugin-contacts 后无法提供应用程序
- c# - 如果我从另一个程序集调用 MainWindow.xaml,则不会加载图像
- c - 在哪里放置 libwebsocket.h 文件
- c# - Inisght.Database 自动存储库和自定义列映射
- python - Flask - 在将数据发送到html之前显示进度条,同时功能进度
- ruby-on-rails - 在 Rails 中,如何响应无关的非 http 请求?
- javascript - 分配数组值给出未定义的键
- r - 在 r 中用于年龄预测的模型