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

推荐订阅源

PCI Perspectives
PCI Perspectives
C
CERT Recently Published Vulnerability Notes
Project Zero
Project Zero
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
T
Threatpost
NISL@THU
NISL@THU
H
Help Net Security
G
Google Developers Blog
S
Securelist
Recorded Future
Recorded Future
云风的 BLOG
云风的 BLOG
MyScale Blog
MyScale Blog
V
Vulnerabilities – Threatpost
C
Cyber Attacks, Cyber Crime and Cyber Security
P
Proofpoint News Feed
T
Tenable Blog
M
MIT News - Artificial intelligence
罗磊的独立博客
WordPress大学
WordPress大学
I
Intezer
V2EX - 技术
V2EX - 技术
Schneier on Security
Schneier on Security
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - 叶小钗
Application and Cybersecurity Blog
Application and Cybersecurity Blog
S
Secure Thoughts
C
Cybersecurity and Infrastructure Security Agency CISA
Recent Announcements
Recent Announcements
S
SegmentFault 最新的问题
有赞技术团队
有赞技术团队
H
Hackread – Cybersecurity News, Data Breaches, AI and More
C
Cisco Blogs
大猫的无限游戏
大猫的无限游戏
D
Darknet – Hacking Tools, Hacker News & Cyber Security
L
Lohrmann on Cybersecurity
The GitHub Blog
The GitHub Blog
The Cloudflare Blog
宝玉的分享
宝玉的分享
腾讯CDC
V
Visual Studio Blog
Google DeepMind News
Google DeepMind News
美团技术团队
H
Heimdal Security Blog
Hugging Face - Blog
Hugging Face - Blog
The Last Watchdog
The Last Watchdog
L
LINUX DO - 热门话题
Spread Privacy
Spread Privacy
博客园 - 司徒正美
博客园 - Franky
W
WeLiveSecurity

博客园 - 魏巍(QQ:68235081)

.Net Core实战教程(三):使用Supervisor配置守护进程 .Net Core实战教程(二):设置Kestrel的IP与端口的几种方法 .Net Core实战教程(一):Linux下搭建项目 windows 2012 IIS 部署 .net core HTTP Error 502.5 - Process Failure 错误解决办法 sqlserver 删除所有记录后,让自增列从1开始 .Net Core 给WebApi接口返回值添加全局的日期格式化 Message "'OFFSET' 附近有语法错误。 在 FETCH 语句中选项 NEXT 的用法无效。" 解决办法 EntityFrameworkCore 关于.Net Core 部署在Linux下连接SqlServer数据库超时解决办法 EntityFrameworkCore Db First 生成Model时出错 PowerShell 版本过低 vs2017添加引用提示“找不到 Microsoft.VisualStudio.Shell.Interop.IVsReferenceManager 服务的实例”解决方案 在.Net Core中使用Swagger制作接口文档 发布mvc遇到的HTTP错误 403.14-Forbidden解决办法 如何在.Net Mvc中让Get,Post请求访问同一个Action的方法 jquery中attr和prop的区别 WebApi验证 解决Code First MySql数据库 Specified key was too long; max key length is 767 bytes异常 【转】Unobtrusive Ajax的使用 jquery.validate.unobtrusive的使用 企业库判断数据库连接类型
关于.Net Core 前后端分离跨域请求时 ajax并发请求导致部分无法通过验证解决办法。
魏巍(QQ:68235081) · 2018-10-10 · via 博客园 - 魏巍(QQ:68235081)

项目中有这样一个页面。页面加载的时候会同时并发6个ajax请求去后端请求下拉框。

这样会导致每次都有1~2个“浏览器预请求”不通过。

浏览器为什么会自动发送“预请求”?请看以面连接

https://blog.csdn.net/charleslei/article/details/51906635

那么解决办法无非就是尽量避免发送“预请求”。

后来经过反复测试发现“预请求”可以通过设置Access-Control-Max-Age来缓存。

在.Net Core 中我们可以通过如下代码设置缓存:

public void ConfigureServices(IServiceCollection services)
        {
            //配置跨域访问
            var urls = Configuration.GetSection("AllowCors:AllowAllOrigin").Value.Split(',');
            services.AddCors(options =>
            {
                options.AddPolicy("AllowAllOrigin", builder =>
                {
                    builder.WithOrigins(urls).AllowAnyMethod().AllowAnyHeader().AllowCredentials().SetPreflightMaxAge(TimeSpan.FromSeconds(1728000));
                });
            });

            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
        }

使用

SetPreflightMaxAge方法设置即可。单位为秒