This request has been blocked because sensitive information is disclosed to third-party Web sites when used in a GET request. To allow a GET request, set Jsonrequestbehavior to Allowget.

Source: Internet
Author: User

1, problem description

MVC gets all the picture information from one path, and the Ajax method is as follows:

functiongetimages (day) {varYear = $ ("#selYear"). Val (); varMonth = $ ("#selMonth"). Val (); Selday=Day ; varDate = year + "." + month + "." + (Day < 10?) "0" +day:day); $("#selInfo"). text (date); $("#fileContainer"). HTML (""); $.ajax ({URL:' @Url. Content ("/medoffice/photo/imagelist") ' + '? path= ' +date, type:' GET ', DataType:' Text/json ', Success:function(data) {alert (data); }, Error:function(XMLHttpRequest, Textstatus, Errorthrown) {console.log (XMLHttpRequest);                alert (XMLHttpRequest);        }            }); }

The call execution returns the following result:

2, problem analysis

Change the JSON to Jsonresult and set to:

Jsonrequestbehavior = jsonrequestbehavior.allowget//Plus this sentence

3. Correct Request method
 PublicJsonresult ImageList (stringpath) {List<FileInfoViewModel> files =NewList<fileinfoviewmodel>(); Try            {                vardatetime =datetime.parse (path); varMyPath = path. Replace (DateTime. Year +".",""); varDestPath ="~/alldocuments/"+ DateTime. Year +"/"+MyPath; DestPath=Server.MapPath (DestPath); if(Directory.Exists (DestPath)) {foreach(stringFilePathinchDirectory.GetFiles (DestPath)) {Fileinfoviewmodel Model=NewFileinfoviewmodel {Path=filepath, Name=path.getfilenamewithoutextension (filepath)}; Try                        {                            varFileInfo =NewFileInfo (filepath); Model. Size=fileInfo.Length.ToString (); Model. Date= FileInfo.CreationTime.ToString ("YYYY-MM-DD HH:mm:ss"); }                        Catch(Exception e) {loghelper.error (e); }                    }                }                return NewJsonresult () {Data=New{result=0, Messate="", the data=files}, Jsonrequestbehavior=Jsonrequestbehavior.allowget}; }            Catch(Exception e) {loghelper.error (e); return NewJsonresult () {Data=New{result= - About, Messate=e.message, Data=files}, Jsonrequestbehavior=Jsonrequestbehavior.allowget}; }        }

This request has been blocked because sensitive information is disclosed to third-party Web sites when used in a GET request. To allow a GET request, set Jsonrequestbehavior to Allowget.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.