Those who use WTM may all encounter cross-domain problems just like me. Obviously, CorsOptions set EnableAll in appsettings.json to true, but when debugging SPA application, a cross-domain error message is still displayed. The solution is as follows:
One, the ConfigureServices method adds content
x.AddCors(options =>
{
options.AddPolicy("all", builder =>
{
builder.SetIsOriginAllowed(_ => true) //允许任何来源的主机访问
.AllowAnyMethod()
.AllowAnyHeader()
.AllowCredentials();//指定处理cookie
});
});
Two, add in the Configure method
x.UseCors("all");
In this way, after restarting the project, WTM cross-domain is realized.
X. If you need to limit access to the source, modify ConfigureServices
services.AddCors(options => options.AddPolicy("CorsPolicy",
builder =>
{
builder.WithOrigins(new string[] { "http://127.0.0.1:5500" })
.AllowAnyMethod()
.AllowAnyHeader()
.AllowCredentials();
}));