c# - 是否可以在 Asp Net Core Api 中使用通配符为部分随机 url 设置 cors 规则?
问题描述
我有一个 Asp Net Core (3.1) Api,我在其中指定了这样的 cors 策略:
public void ConfigureServices(IServiceCollection services)
{
services.AddCors(options =>
{
options.AddPolicy(name: "MyPolicy",
builder =>
{
builder.WithOrigins("https://myurl.com",
)
.AllowAnyMethod()
.AllowAnyHeader()
.AllowCredentials())
});
});
}
但是,我希望能够允许任何包含“myurl”的来源,即使它有不同的开始或结束,只要它包含“myurl”。
例如,应该允许 https://adifferentstartthenmyurl.com 例如,最好也应该允许https://myurladifferentend.com 。
这在 net core 3.1 cors 规则中是否支持?是否可以指定这样的 cors 策略?
我希望能够使用类似的东西:
public void ConfigureServices(IServiceCollection services)
{
services.AddCors(options =>
{
options.AddPolicy(name: "MyPolicy",
builder =>
{
builder.WithOrigins("https://*myurl*.com",
)
.AllowAnyMethod()
.AllowAnyHeader()
.AllowCredentials())
});
});
}
使用 * 作为通配符说明符。
解决方案
推荐阅读
- perl - perl -pe "s|$PASSWORD| 是什么意思?
|g”? - node.js - 如何使用 innodb_log_file_size 增加重做日志大小?
- android - 将大图像叠加到像 snapchat 这样的小视频上
- java - Windowed Store 未填满(Spring Cloud Stream Kafka)
- sql - 如何为 SQL 变量赋值
- dns - NS 变化传播
- spring-boot - 如何使用 Spring EntityLinks 创建指向 /profiles/{user-id}/job URI 的 REST 链接?
- javascript - 如何使用请求模块提出与此表单相同的请求?
- python - 从字典字典中提取值
- android - XML-drawable 使用图层列表无法正常工作