hutongqing
2024-10-25 d85a4b97325020b7efe1a6cdbd55025c6408cec9
WIDESEAWCS_Server/WIDESEAWCS_Core/Middlewares/SwaggerAuthMiddleware.cs
@@ -6,6 +6,7 @@
using System.Net;
using System.Text;
using System.Threading.Tasks;
using WIDESEAWCS_Core.Extensions;
namespace WIDESEAWCS_Core.Middlewares
{
@@ -22,7 +23,7 @@
        public async Task InvokeAsync(HttpContext context)
        {
            // 也可以根据是否是本地做判断 IsLocalRequest
            if (context.Request.Path.Value.ToLower().Contains("index.html"))
            if (context.Request.Path.Value?.ToLower().Contains("index.html") ?? false)
            {
                // 判断权限是否正确
                if (IsAuthorized(context))
@@ -32,7 +33,7 @@
                }
                // 无权限,跳转swagger登录页
                context.Response.Redirect("/swg-login.html");
                context.RedirectSwaggerLogin();
            }
            else
            {
@@ -44,7 +45,7 @@
        {
            // 使用session模式
            // 可以使用其他的
            return context.Session.GetString("swagger-code") == "success";
            return context.IsSuccessSwagger();
        }
        /// <summary>
@@ -59,7 +60,7 @@
            {
                return true;
            }
            if (context.Connection.RemoteIpAddress.Equals(context.Connection.LocalIpAddress))
            if (context.Connection.RemoteIpAddress?.Equals(context.Connection.LocalIpAddress) ?? false)
            {
                return true;
            }