ABP问题集结
- 添加js跨域访问。
在Startup.cs文件中 public IServiceProvider ConfigureServices(IServiceCollection services)中添加
services.AddCors( options => options.AddPolicy( "AlloweDomain", builder => builder .WithOrigins( // App:CorsOrigins in appsettings.json can contain more than one address separated by comma. _appConfiguration["App:CorsOrigins"] .Split(",", StringSplitOptions.RemoveEmptyEntries) .Select(o => o.RemovePostFix("/")) .ToArray() ) .AllowAnyHeader() .AllowAnyMethod() .AllowCredentials() ) );
在允许跨域的Controller中添加。也可以在ControllerBase中添加允许全部继承继承类的Controller。
[EnableCors("AlloweDomain")] public class FileGetController : ServiceControllerBase { }
在appsettings.json添加允许访问的域名。
"App": { "CorsOrigins": "http://localhost:4200,http://localhost:8080,http://localhost:8081,https://www.baidu.com" },