惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

S
Schneier on Security
有赞技术团队
有赞技术团队
T
The Blog of Author Tim Ferriss
F
Fortinet All Blogs
D
DataBreaches.Net
F
Full Disclosure
腾讯CDC
博客园 - 【当耐特】
MyScale Blog
MyScale Blog
Stack Overflow Blog
Stack Overflow Blog
小众软件
小众软件
Hugging Face - Blog
Hugging Face - Blog
Last Week in AI
Last Week in AI
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
爱范儿
爱范儿
The GitHub Blog
The GitHub Blog
Engineering at Meta
Engineering at Meta
大猫的无限游戏
大猫的无限游戏
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
S
SegmentFault 最新的问题
The Register - Security
The Register - Security
WordPress大学
WordPress大学
博客园 - 聂微东
雷峰网
雷峰网
J
Java Code Geeks
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
P
Privacy International News Feed
酷 壳 – CoolShell
酷 壳 – CoolShell
A
Arctic Wolf
Scott Helme
Scott Helme
C
Cyber Attacks, Cyber Crime and Cyber Security
T
Tor Project blog
博客园 - 三生石上(FineUI控件)
Know Your Adversary
Know Your Adversary
AWS News Blog
AWS News Blog
G
Google Developers Blog
www.infosecurity-magazine.com
www.infosecurity-magazine.com
C
CERT Recently Published Vulnerability Notes
O
OpenAI News
Project Zero
Project Zero
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Application and Cybersecurity Blog
Application and Cybersecurity Blog
云风的 BLOG
云风的 BLOG
N
News and Events Feed by Topic
MongoDB | Blog
MongoDB | Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Microsoft Security Blog
Microsoft Security Blog
Cisco Talos Blog
Cisco Talos Blog
P
Palo Alto Networks Blog
Schneier on Security
Schneier on Security

博客园 - 迪克猪

发布一款vscode仓颉文件图标显示插件Mosmmy Cangjie Icons 在 Mac、Linux、Windows 下Go交叉编译 用户中心 - 博客园 golang字节数组拷贝BlockCopy函数实现 go module下golang.org如何处理被墙 go: writing stat cache:, permission denied mac os下不同工具go env下gopath显示不同 异类查询要求为连接设置ANSI_NULLS和ANSI_WARNINGS选项 SetProcessWorkingSetSize减少内存占用 mac os系统go安装:go install github.com/nsf/gocode: open /usr/local/go/bin/gocode: permission denied vscode打造最佳的markdown编辑器 "title_activity_dist" is not translated in "zh-rCN" (Chinese: China) android sdk manager更新地址 vscode圣诞帽 阿里java代码检测工具p3c elasticsearch 二、elasticsearch-head安装 elasticsearch 一、环境配置 针对json的查询--alibaba的开源项目jsonq macos下golang 1.9配置
此请求已被阻止,因为当用在 GET 请求中时,会将敏感信息透漏给第三方网站。若要允许 GET 请求,请将 JsonRequestBehavior 设置为 AllowGet。
迪克猪 · 2017-06-25 · via 博客园 - 迪克猪

1、问题描述

mvc从一个路径获取所有的图片信息,ajax方法如下:

function getimages(day) {
            var year = $("#selYear").val();
            var month = $("#selMonth").val();
            selday = day;
            var date = 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);
                }
            });
        }

调用执行返回如下结果:

image

2、问题分析

image

将json更改为jsonresult并设置为:

JsonRequestBehavior = JsonRequestBehavior.AllowGet//加上这一句

3、正确请求方法

public JsonResult ImageList(string path)
        {
            List<FileInfoViewModel> files = new List<FileInfoViewModel>();

            try
            {
                var datetime = DateTime.Parse(path);
                var mypath = path.Replace(datetime.Year + ".", "");
                var destpath = "~/AllDocuments/" + datetime.Year + "/" + mypath;
                destpath = Server.MapPath(destpath);
                if (Directory.Exists(destpath))
                {
                    foreach (string filepath in Directory.GetFiles(destpath))
                    {
                        FileInfoViewModel model = new FileInfoViewModel
                        {
                            Path = filepath,
                            Name = Path.GetFileNameWithoutExtension(filepath)
                        };
                        try
                        {
                            var fileInfo = new FileInfo(filepath);
                            model.Size = fileInfo.Length.ToString();
                            model.Date = fileInfo.CreationTime.ToString("yyyy-MM-dd HH:mm:ss");
                        }
                        catch (Exception e)
                        {
                            LogHelper.Error(e);
                        }
                    }
                }

                return new JsonResult()
                {
                    Data = new
                    {
                        result = 0,
                        messate = "",
                        data = files
                    },
                    JsonRequestBehavior = JsonRequestBehavior.AllowGet
                };
            }
            catch (Exception e)
            {
                LogHelper.Error(e);
                return new JsonResult()
                {
                    Data = new
                    {
                        result = -99,
                        messate = e.Message,
                        data = files
                    },
                    JsonRequestBehavior = JsonRequestBehavior.AllowGet
                };
            }
        }