Request Has Been Blocked Because Sensitive Information In MVC JsonResult

Sometime when return JsonResult in MVC ,"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. error is occurred."

The reason of this error is request made with Get request and by default GET request from user is not allowed in JsonResult , So to solve this issue we need to set JsonRequestBehavior to AllowGet.

The following code will cause the error
[HttpGet]
        public JsonResult GetData()
        {
            List<string> a = new List<string>();
            a.Add("A");

            return Json(a);

        }

The above code cause error ,"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. error is occurred.

Solution

To solve the above error just we need to set JsonRequestBehavior to AllowGet in json method ,the following is the code which will solve our issue.

[HttpGet]
        public JsonResult GetData()
        {
         List<string> a = new List<string>();
            a.Add("A");

            return Json(a, JsonRequestBehavior.AllowGet);
        }

In the above method we see that ,we have set another extra parameter in json method that is JsonRequestBehavior.AllowGet.
Watch Video

Summary 
I hope this article is useful for all readers if you have any suggestion related to this article then please contact me.
Download Aspose : API To Create and Convert Files





Post a Comment

www.CodeNirvana.in

Protected by Copyscape Online Copyright Protection
Copyright © Compile Mode