| 
						
						
						
					 | 
					 | 
					@ -1,5 +1,6 @@
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					using System.Text;
 | 
					 | 
					 | 
					 | 
					using System.Net;
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					using System.Text.RegularExpressions;
 | 
					 | 
					 | 
					 | 
					using System.Text;
 | 
				
			
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					using System.Web;
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					using Microsoft.AspNetCore.Http;
 | 
					 | 
					 | 
					 | 
					using Microsoft.AspNetCore.Http;
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					namespace NPin.Framework.Core.Extensions;
 | 
					 | 
					 | 
					 | 
					namespace NPin.Framework.Core.Extensions;
 | 
				
			
			
		
	
	
		
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
					 | 
					@ -13,9 +14,8 @@ public static class HttpContextExtensions
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    /// <param name="fileName"></param>
 | 
					 | 
					 | 
					 | 
					    /// <param name="fileName"></param>
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    public static void FileInlineHandle(this HttpContext httpContext, string fileName)
 | 
					 | 
					 | 
					 | 
					    public static void FileInlineHandle(this HttpContext httpContext, string fileName)
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    {
 | 
					 | 
					 | 
					 | 
					    {
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            string encodeFilename = System.Web.HttpUtility.UrlEncode(fileName, Encoding.GetEncoding("UTF-8"));
 | 
					 | 
					 | 
					 | 
					        string encodeFilename = HttpUtility.UrlEncode(fileName, Encoding.GetEncoding("UTF-8"));
 | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        httpContext.Response.Headers.Add("Content-Disposition", "inline;filename=" + encodeFilename);
 | 
					 | 
					 | 
					 | 
					        httpContext.Response.Headers.Add("Content-Disposition", "inline;filename=" + encodeFilename);
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    }
 | 
					 | 
					 | 
					 | 
					    }
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    /// <summary>
 | 
					 | 
					 | 
					 | 
					    /// <summary>
 | 
				
			
			
		
	
	
		
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
					 | 
					@ -25,9 +25,8 @@ public static class HttpContextExtensions
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    /// <param name="fileName"></param>
 | 
					 | 
					 | 
					 | 
					    /// <param name="fileName"></param>
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    public static void FileAttachmentHandle(this HttpContext httpContext, string fileName)
 | 
					 | 
					 | 
					 | 
					    public static void FileAttachmentHandle(this HttpContext httpContext, string fileName)
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    {
 | 
					 | 
					 | 
					 | 
					    {
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            string encodeFilename = System.Web.HttpUtility.UrlEncode(fileName, Encoding.GetEncoding("UTF-8"));
 | 
					 | 
					 | 
					 | 
					        string encodeFilename = HttpUtility.UrlEncode(fileName, Encoding.GetEncoding("UTF-8"));
 | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        httpContext.Response.Headers.Add("Content-Disposition", "attachment;filename=" + encodeFilename);
 | 
					 | 
					 | 
					 | 
					        httpContext.Response.Headers.Add("Content-Disposition", "attachment;filename=" + encodeFilename);
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    }
 | 
					 | 
					 | 
					 | 
					    }
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    /// <summary>
 | 
					 | 
					 | 
					 | 
					    /// <summary>
 | 
				
			
			
		
	
	
		
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
					 | 
					@ -43,8 +42,8 @@ public static class HttpContextExtensions
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        {
 | 
					 | 
					 | 
					 | 
					        {
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            res = str.Split(",")[0];
 | 
					 | 
					 | 
					 | 
					            res = str.Split(",")[0];
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        }
 | 
					 | 
					 | 
					 | 
					        }
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            return res;
 | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        return res;
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    }
 | 
					 | 
					 | 
					 | 
					    }
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    /// <summary>
 | 
					 | 
					 | 
					 | 
					    /// <summary>
 | 
				
			
			
		
	
	
		
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
					 | 
					@ -57,31 +56,65 @@ public static class HttpContextExtensions
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        string header = request.Headers["X-Requested-With"];
 | 
					 | 
					 | 
					 | 
					        string header = request.Headers["X-Requested-With"];
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        return "XMLHttpRequest".Equals(header);
 | 
					 | 
					 | 
					 | 
					        return "XMLHttpRequest".Equals(header);
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    }
 | 
					 | 
					 | 
					 | 
					    }
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    /// <summary>
 | 
					 | 
					 | 
					 | 
					    /// <summary>
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        /// 获取客户端IP
 | 
					 | 
					 | 
					 | 
					    /// 获取客户端Ip
 | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    /// </summary>
 | 
					 | 
					 | 
					 | 
					    /// </summary>
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    /// <param name="context"></param>
 | 
					 | 
					 | 
					 | 
					    /// <param name="context"></param>
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    /// <returns></returns>
 | 
					 | 
					 | 
					 | 
					    /// <returns></returns>
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        public static string GetClientIp(this HttpContext context)
 | 
					 | 
					 | 
					 | 
					    public static string GetClientIp(this HttpContext? context)
 | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    {
 | 
					 | 
					 | 
					 | 
					    {
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        if (context == null) return "";
 | 
					 | 
					 | 
					 | 
					        if (context == null) return "";
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        var result = context.Request.Headers["X-Forwarded-For"].FirstOrDefault();
 | 
					 | 
					 | 
					 | 
					        var result = context.Request.Headers["X-Forwarded-For"].FirstOrDefault();
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        if (string.IsNullOrEmpty(result))
 | 
					 | 
					 | 
					 | 
					        if (string.IsNullOrEmpty(result))
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        {
 | 
					 | 
					 | 
					 | 
					        {
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            result = context.Connection.RemoteIpAddress?.ToString();
 | 
					 | 
					 | 
					 | 
					            result = context.Connection.RemoteIpAddress?.ToString();
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        }
 | 
					 | 
					 | 
					 | 
					        }
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            if (string.IsNullOrEmpty(result) || result.Contains("::1"))
 | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                result = "127.0.0.1";
 | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            result = result.Replace("::ffff:", "127.0.0.1");
 | 
					 | 
					 | 
					 | 
					        // 解析 Ip String 到 Ipv4 或 MapToIPv4
 | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        // 若无法解析 IP String,强制转为本地 Ipv4
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        result = IPAddress.TryParse(result, out var ipAddr)
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					            ? ipAddr.MapToIPv4().ToString()
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					            : IPAddress.Loopback.ToString();
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            //Ip规则效验
 | 
					 | 
					 | 
					 | 
					        // // 本地回环 转换为 ipv4 127.0.0.1
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            var regResult = Regex.IsMatch(result, @"^((2[0-4]\d|25[0-5]|[01]?\d\d?)\.){3}(2[0-4]\d|25[0-5]|[01]?\d\d?)$");
 | 
					 | 
					 | 
					 | 
					        // if (string.IsNullOrEmpty(result) || result.Contains("::1"))
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					        // {
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            result = regResult ? result : "127.0.0.1";
 | 
					 | 
					 | 
					 | 
					        //     result = "127.0.0.1";
 | 
				
			
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        // }
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        //
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        // result = result.Replace("::ffff:", "127.0.0.1");
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        //
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        // // Ip规则效验
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        // var regResult = Regex.IsMatch(result, @"^((2[0-4]\d|25[0-5]|[01]?\d\d?)\.){3}(2[0-4]\d|25[0-5]|[01]?\d\d?)$");
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        //
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        // result = regResult ? result : "127.0.0.1";
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        return result;
 | 
					 | 
					 | 
					 | 
					        return result;
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    }
 | 
					 | 
					 | 
					 | 
					    }
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					    /// <summary>
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					    /// 获取客户端Ip
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					    /// </summary>
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					    /// <param name="context"></param>
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					    /// <returns></returns>
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					    public static IPAddress? GetClientIpAddress(this HttpContext? context)
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					    {
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        if (context == null) return null;
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        var result = context.Request.Headers["X-Forwarded-For"].FirstOrDefault();
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        if (string.IsNullOrEmpty(result))
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        {
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					            result = context.Connection.RemoteIpAddress?.ToString();
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        }
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        // 解析 Ip String 到 IpAddress
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        // 若无法解析 IP String,强制转为本地 Ipv4
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        return IPAddress.TryParse(result, out var ipAddr)
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					            ? ipAddr
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					            : IPAddress.Loopback;
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					    }
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    /// <summary>
 | 
					 | 
					 | 
					 | 
					    /// <summary>
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    /// 获取浏览器标识
 | 
					 | 
					 | 
					 | 
					    /// 获取浏览器标识
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    /// </summary>
 | 
					 | 
					 | 
					 | 
					    /// </summary>
 | 
				
			
			
		
	
	
		
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
					 | 
					@ -92,7 +125,7 @@ public static class HttpContextExtensions
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        return context.Request.Headers["User-Agent"];
 | 
					 | 
					 | 
					 | 
					        return context.Request.Headers["User-Agent"];
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    }
 | 
					 | 
					 | 
					 | 
					    }
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        public static string[]? GetUserPermissions(this HttpContext context, string permissionsName)
 | 
					 | 
					 | 
					 | 
					    public static string[] GetUserPermissions(this HttpContext context, string permissionsName)
 | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    {
 | 
					 | 
					 | 
					 | 
					    {
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        return context.User.Claims.Where(x => x.Type == permissionsName).Select(x => x.Value).ToArray();
 | 
					 | 
					 | 
					 | 
					        return context.User.Claims.Where(x => x.Type == permissionsName).Select(x => x.Value).ToArray();
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    }
 | 
					 | 
					 | 
					 | 
					    }
 | 
				
			
			
		
	
	
		
		
			
				
					| 
						
						
						
					 | 
					 | 
					
 
 |