标签:developer 跨域 map control except develop style routing end
在Startup文件的ConfigureServices函数里注入服务
public void ConfigureServices(IServiceCollection services) { #region Cors跨域请求 services.AddCors(c => { c.AddPolicy("AllRequests", policy => { policy .AllowAnyOrigin() .AllowAnyMethod() .AllowAnyHeader(); }); }); #endregion services.AddControllers(); }
在其后的Configure函数中开启中间件
public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseRouting(); //开启Cors跨域请求中间件 app.UseCors("AllRequests"); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); }
标签:developer 跨域 map control except develop style routing end
原文地址:https://www.cnblogs.com/tommao2618/p/13151790.html