This article is a mirror article of machine translation, please click here to jump to the original article.

View: 16873|Reply: 1

[ASP.NET] get request JsonResult error. There was an error processing your request.

[Copy link]
Posted on 1/4/2016 12:08:44 PM | | | |


I access directly with the browser, and it will report an error.

Let's take a look at what is JsonResult?

JsonResult: JsonResult has a property of type Data that represents the data object that needs to be converted to JSON format. The properties ContentEncoding and ContentType are the encoding methods and media types of the current response settings, and the default media type is application/json.

Remark:
For security reasons, JsonResult cannot be used as a response to an HTTP-GET request by default, in which case an InvalidOperationException exception will be thrown directly. We can enable JsonResult support for HTTP-GET requests through its JsonRequestBehavior property. The property type is JsonRequestBehavior enumeration, and the two enums, AllowGet and DenyGet, respectively, indicate allow/deny support for responses to HTTP-GET requests. The JsonRequestBehavior property of JsonResult is set to DenyGet when initialized, and if we need to respond to HTTP-GET requests with the created JsonResult, we need to explicitly set its JsonRequestBehavior property to AllowGet.


Therefore, the reason for the error is the get request we use, everyone understands, just replace it with post




Previous:How to learn easy language
Next:C# implements the function of sending emails
 Landlord| Posted on 1/4/2016 12:13:50 PM |
Or add JsonRequestBehavior.AllowGet
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com