asp .net mvc exception To allow GET requests set JsonRequestBehavior to AllowGet Edit
In my asp .net mvc application I wrote an action method to return JSON using action result return JSON method. And it was throwing this error To allow GET requests, set JsonRequestBehavior to AllowGet.
Exception Details
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.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidOperationException: 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.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Solution
The solution was to modify the code and pass the second parameter JsonRequestBehavior.AllowGet
public ActionResult GetNameImage() { var retval = new SetupIngredient(Common.ConnectionString).GetNameImage(); return Json(retval, JsonRequestBehavior.AllowGet); }