此请求已被阻止,因为当在 GET 请求中使用时,敏感信息可能会泄露给第三方网站。

This request has been blocked because sensitive information could be disclosed to third party web sites when this is used in a GET request.

我想用 ajax 从控制器中获取 'Blog Entry' 和 'Blog Entry Photo'。当只取 'BlogEntry' 时没有任何问题,另一方面,当同时使用它们(BlogEntry 和 BlogEntryPhoto)时,有问题:"This request has been blocked because sensitive information could be disclosed to third party web sites when this is used in a GET request. To allow GET requests, set JsonRequestBehavior to AllowGet."

我认为问题出在 'Blog Entry Photo',因为它有像“/Content/img/blog/25052017_2334_400x400.jpg”这样的 photopath 列。 我使用了 JsonResult 但它不起作用

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

我该怎么办?

最后,我最终解决了这个由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
      }
});