【问题标题】:This request has been blocked because sensitive information could be disclosed to third party web sites when this is used in a GET request.此请求已被阻止,因为在 GET 请求中使用敏感信息可能会泄露给第三方网站。
【发布时间】:2018-01-28 17:14:11
【问题描述】:

我想使用 ajax 从控制器中获取“博客条目”和“博客条目照片”。只取'BlogEntry'时没有任何问题,另一方面,当同时取两者(BlogEntry 和BlogEntryPhoto)时,有一个问题:“此请求已被阻止,因为敏感信息可能会泄露给第三方用于 GET 请求的网站。要允许 GET 请求,请将 JsonRequestBehavior 设置为 AllowGet。"

我认为问题出在“博客条目照片”中,因为它具有像“/Content/img/blog/25052017_2334_400x400.jpg”这样的 photopath 列。 我使用了 JsonResult 但它不起作用

return Json(new { Success = true, BlogEntries = blogEntries, BlogEntryPhotos = blogEntryPhotos}, JsonRequestBehavior.AllowGet);

我该怎么办?

【问题讨论】:

  • 在 VS,由于断点,我检查了数据是否被客户端获取,但数据被获取。我认为问题出在 PhotoPath 因为 AJAX 的 MIMETYPE。

标签: ajax asp.net-mvc http-post jsonresult


【解决方案1】:

最后,我最终解决了这个由 PhotoPath 数据引起的问题。首先,在控制器中,BlogEntry 和 BlogEntryPhotos 的数据一起被序列化,然后在视图中将这些数据解析为对象。

控制器

List<BlogEntry> blogEntries = _blogEntryRepo.GetAll(x => x.IsActive.Value && x.PlaceMarkerID == placeMarker.Id, null, "BlogEntryPhotoes").ToList();
JsonSerializerSettings jss = new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore };
return Json(new { Success = true, BlogEntries = JsonConvert.SerializeObject(blogEntries, Formatting.Indented, jss) }, JsonRequestBehavior.AllowGet);

查看

$.ajax({
      url: "/Map/GetBlogEntries",
      type: "post",
      datatype: "json",
      data: placeMarker,
      success: function (response) {
        if (response.Success) { 
             var BlogEntries = JSON.parse( response.BlogEntries );
             //BlogEntries[i].Title can be used
             //BlogEntries[i].BlogEntryPhotoes[0].PhotoPath can be used
        }
        else {
                //do something
    }
      },
      error: function (xhr, status) {
        //do something
      }
});

【讨论】:

    猜你喜欢
    • 2017-09-01
    • 1970-01-01
    • 2018-12-31
    • 2014-02-22
    • 2020-12-19
    • 2015-12-17
    • 1970-01-01
    • 2017-01-09
    • 2016-03-15
    相关资源
    最近更新 更多