当前位置:网站首页>Cross domain problems in the configuration of.Net core version 3.1
Cross domain problems in the configuration of.Net core version 3.1
2022-07-28 15:20:00 【A grain of sand in the sea】
1、Startup Content
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration {
get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
// Configure cross domain processing , Allow all sources
services.AddCors(options =>
{
options.AddPolicy("cors", builder =>
{
builder.AllowAnyOrigin() // Allow host access from any source
.AllowAnyMethod()
.AllowAnyHeader();
//.AllowCredentials();// Specify treatment cookie
});
});
// Cross domain configuration end
services.AddControllers();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseHttpsRedirection();
app.UseRouting();
// Allow all cross domains ,cors Is in ConfigureServices Method
// Be careful :UseCors Must be on UseRouting and UseEndpoints Between
app.UseCors("cors");
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
// Cross domain needs to be added RequireCors Method ,cors Is in ConfigureServices Method
endpoints.MapControllers().RequireCors("cors");
});
}
}
2、 Detailed instructions ,ConfigureServices To configure
// Configure cross domain processing , Allow all sources
services.AddCors(options =>
{
options.AddPolicy("cors", builder =>
{
builder.AllowAnyOrigin() // Allow host access from any source
.AllowAnyMethod()
.AllowAnyHeader();
//.AllowCredentials();// Specify treatment cookie
});
});
3、Configure To configure
// Allow all cross domains ,cors Is in ConfigureServices Method
// Be careful :UseCors Must be on UseRouting and UseEndpoints Between
app.UseCors("cors");
// Cross domain needs to be added RequireCors Method ,cors Is in ConfigureServices Method
endpoints.MapControllers().RequireCors("cors");
4、 Be careful
(1) UseCors Must be on UseRouting and UseEndpoints Between , Particular attention , Order matters
(2).net core 2.2 and 3.1 Version cross domain configuration is different
Use 2.2 Version method configuration , stay 3.1 The version will appear Not all cross domain
5、 see .net core 2.2 Version cross domain configuration
6、.net Cross domain method configuration official document , You can have a look at what you need Click to see
边栏推荐
- Enterprise wechat customer service link, enterprise wechat customer service chat
- Classic Dijkstra and the longest way
- 使用cpolar发布树莓派网页(apache2的安装测试)
- 代码比较干净的多商户商城系统
- idea调试burpsuit插件
- PMP【敏捷教材+全真模拟题】,续6月25日考试之后,敏捷就成为了重中
- 3438. 数制转换
- celery 相关
- Three pain points of software development! How to solve the applet container?
- 【LeetCode】35、搜索插入位置
猜你喜欢

No files or folders found to process

Requses template

Install MOSEK, license installation location search

In 2022, the average salary of global programmers was released, and China ranked unexpectedly

Have you ever used the single merchant mall, which is smooth enough to make people feel numb?

Here comes the full open source free customer service system

Instructions for common symbols in kotlin

Jy-7ga/1 voltage relay

idea调试burpsuit插件

mysql 8.0常用(持续更新)
随机推荐
Feeling about software development work in the second anniversary
[MP error] MP: 'getbasemappe serviceimpl' claims
JOGY-61电压继电器
Xiaobai can understand the 35 necessary questions in MySQL interview
shellcode编写(未完)
树上启发式合并简单题
回编译失败
What is the difference between UTF-8, utf-16 and UTF-32 character encoding? [graphic explanation]
mysql 8.0常用(持续更新)
3715. 最少交换次数
crmeb pro2.2即将增加的功能都有哪些?
pyppeteer 遇到的问题
Dj-131/60c voltage relay
3511. 倒水问题
Mysql易错知识点整理(待更新)
网络安全应急响应具体操作流程
为什么企业需要用户自治的数字身 份
4519. Number of square arrays
How to set some app application icons on the iPhone Apple phone that you don't want others to see? How to hide the app application settings on the mobile desktop so that they can be used normally afte
Voltage relay dy-28c