yinyafei пре 3 година
родитељ
комит
d25a20ca12

+ 2 - 0
PMS.NetCore/PMS.NetCore/Controllers/ElectronicInspectionController.cs

@@ -1,4 +1,5 @@
 using Microsoft.AspNetCore.Authorization;
+using Microsoft.AspNetCore.Cors;
 using Microsoft.AspNetCore.Hosting;
 using Microsoft.AspNetCore.Http;
 using Microsoft.AspNetCore.Mvc;
@@ -20,6 +21,7 @@ namespace PMS.NetCore.Controllers
     /// <summary>
     /// 电子巡查
     /// </summary>
+    [EnableCors("MyPolicy")]
     [Produces("application/json;charset=UTF-8")]
     [Route("api/ElectronicInspection")]
     [ServiceFilter(typeof(Filter.TokenAuthorize))]

+ 2 - 0
PMS.NetCore/PMS.NetCore/Controllers/UserController.cs

@@ -138,6 +138,8 @@ namespace PMS.NetCore.Controllers
                     ErrMsg = "密码错误"
 
                 };
+                logger.Info($"【ValidateUser】角色:{JsonConvert.SerializeObject(res1)}");
+
                 return Json(res1);
 
 

+ 9 - 6
PMS.NetCore/PMS.NetCore/Startup.cs

@@ -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部署

+ 1 - 1
PMS.NetCore/PMS.NetCore/appsettings.json

@@ -1,5 +1,5 @@
 {
-  "isIIS": false,
+  "isIIS": true,
   "virtualPath": "/wycore",
   "company": "kunshan", //系统属于哪个公司
   "kunshanUrl": "https://www.s-p-c.com.cn/scc2/user/?route=communityActivity/sendWXMsg", //昆山提供的短信接口地址