|
@@ -110,11 +110,12 @@ namespace PMS.NetCore
|
|
|
services.TryAddSingleton<IHttpContextAccessor, HttpContextAccessor>();
|
|
|
services.AddHttpContextAccessor();
|
|
|
|
|
|
- #region 跨域
|
|
|
- services.AddCors(options =>
|
|
|
- options.AddPolicy("AllowSameDomain",
|
|
|
- builder => builder.WithOrigins().AllowAnyMethod().AllowAnyHeader().AllowAnyOrigin().AllowCredentials()));
|
|
|
- #endregion
|
|
|
+ //#region 跨域
|
|
|
+ //services.AddCors(options =>
|
|
|
+ //options.AddPolicy("AllowSameDomain",
|
|
|
+ //builder => builder.WithOrigins().AllowAnyMethod().AllowAnyHeader().AllowAnyOrigin().AllowCredentials()));
|
|
|
+ //#endregion
|
|
|
+
|
|
|
//HttpContextAccessor 默认实现了它简化了访问HttpContext
|
|
|
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
|
|
|
#endregion
|
|
@@ -187,12 +188,14 @@ namespace PMS.NetCore
|
|
|
|
|
|
app.UseRouting();
|
|
|
|
|
|
+ app.UseCors("MyPolicy");
|
|
|
+
|
|
|
app.UseAuthorization();
|
|
|
app.UseSession(); //UseSession配置在 UseMvc 之前
|
|
|
|
|
|
app.UseEndpoints(endpoints =>
|
|
|
{
|
|
|
- endpoints.MapControllers();
|
|
|
+ endpoints.MapControllers().RequireCors("MyPolicy");
|
|
|
});
|
|
|
app.UseSwagger();
|
|
|
if (isIIS == false) //若不是IIS部署
|