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

推荐订阅源

Simon Willison's Weblog
Simon Willison's Weblog
G
Google Developers Blog
Spread Privacy
Spread Privacy
I
InfoQ
V
V2EX
S
Schneier on Security
小众软件
小众软件
C
CERT Recently Published Vulnerability Notes
博客园 - 聂微东
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Stack Overflow Blog
Stack Overflow Blog
T
Threat Research - Cisco Blogs
L
Lohrmann on Cybersecurity
Recent Announcements
Recent Announcements
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Attack and Defense Labs
Attack and Defense Labs
云风的 BLOG
云风的 BLOG
The Hacker News
The Hacker News
S
SegmentFault 最新的问题
C
Cybersecurity and Infrastructure Security Agency CISA
NISL@THU
NISL@THU
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
GbyAI
GbyAI
Latest news
Latest news
S
Secure Thoughts
Project Zero
Project Zero
MongoDB | Blog
MongoDB | Blog
I
Intezer
Security Latest
Security Latest
Apple Machine Learning Research
Apple Machine Learning Research
Vercel News
Vercel News
N
Netflix TechBlog - Medium
V2EX - 技术
V2EX - 技术
量子位
T
Threatpost
T
The Blog of Author Tim Ferriss
Y
Y Combinator Blog
T
Tor Project blog
A
Arctic Wolf
Microsoft Security Blog
Microsoft Security Blog
T
The Exploit Database - CXSecurity.com
大猫的无限游戏
大猫的无限游戏
T
Tailwind CSS Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
C
Check Point Blog
博客园 - Franky
Google DeepMind News
Google DeepMind News
The Register - Security
The Register - Security
The GitHub Blog
The GitHub Blog
L
LINUX DO - 热门话题

博客园 - 迪克猪

发布一款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
                };
            }
        }