update ZR.Admin.WebApi

This commit is contained in:
不做码农 2022-04-09 15:18:20 +08:00
parent 1daa137d98
commit ed483d8b56
2 changed files with 58 additions and 138 deletions

View File

@ -1,70 +0,0 @@
using Common;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using NLog;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace ZRAdmin.Middleware
{
public class RequestIPMiddleware
{
private readonly RequestDelegate _next;
static readonly Logger Logger = LogManager.GetCurrentClassLogger();//声明NLog变量
public RequestIPMiddleware(RequestDelegate next)
{
_next = next;
}
public async Task Invoke(HttpContext context)
{
var url = context.Request.Path.ToString().ToLower();
string userip = Tools.GetRealIP();
//string agent = HttpContextExtension.GetUserAgent(context);
string[] urls = new string[] { "/css", "/js", "/images", "/lib", "/home/error", "/api" };
var strRegex = "(.jpg|.png|.gif|.php|.cfg|.ico)$"; //用于验证图片扩展名的正则表达式
var re = new Regex(strRegex);
//阻止.php访问往下请求
if (new Regex("(.php)$").IsMatch(url))
{
await context.Response.WriteAsync("hello");
return;
}
//var ip_info = IpTool.Search(userip);
////bool flag = ((IList)urls).Contains(url);
//if (!re.IsMatch(url) )
//{
Logger.Debug($"IP中间件请求访问IP[{userip}]");
//}
//两种方式传递下去 一是invoke 一个直接next
//await _next.Invoke(context);
await _next(context);
}
}
public static class RequestIPMiddlewareExtensions
{
/// <summary>
/// 用于引用请求IP中间件
/// </summary>
/// <param name="builder">扩展类型</param>
/// <returns>IApplicationBuilder</returns>
public static IApplicationBuilder UseRequestIPMiddleware(this IApplicationBuilder builder)
{
return builder.UseMiddleware<RequestIPMiddleware>();
}
}
}

View File

@ -1,79 +1,69 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<UserSecretsId>bc51af00-60b6-4e2a-935e-267c368c890a</UserSecretsId>
<EnableNETAnalyzers>false</EnableNETAnalyzers>
<SatelliteResourceLanguages>zh-Hans</SatelliteResourceLanguages>
</PropertyGroup>
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<UserSecretsId>bc51af00-60b6-4e2a-935e-267c368c890a</UserSecretsId>
<EnableNETAnalyzers>false</EnableNETAnalyzers>
<SatelliteResourceLanguages>zh-Hans</SatelliteResourceLanguages>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DocumentationFile>ZRAdmin.xml</DocumentationFile>
<NoWarn>1701;1702;1591;1570</NoWarn>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DocumentationFile>ZRAdmin.xml</DocumentationFile>
<NoWarn>1701;1702;1591;1570</NoWarn>
</PropertyGroup>
<ItemGroup>
<Compile Remove="Filters\GlobalExceptionFilter.cs" />
<Compile Remove="Middleware\RequestIPMiddleware.cs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="AspNetCoreRateLimit" Version="4.0.2" />
<PackageReference Include="EPPlus" Version="5.8.6" />
<PackageReference Include="Hei.Captcha" Version="0.3.0" />
<PackageReference Include="IPTools.China" Version="1.6.0" />
<PackageReference Include="CSRedisCore" Version="3.6.9" />
<PackageReference Include="Mapster" Version="7.3.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="5.0.0" NoWarn="NU1605" />
<PackageReference Include="NETCore.Encrypt" Version="2.1.0" />
<PackageReference Include="NLog" Version="4.7.14" />
<PackageReference Include="NLog.Web.AspNetCore" Version="4.14.0" />
<PackageReference Include="Snowflake.Core" Version="2.0.0" />
<PackageReference Include="SqlSugar.IOC" Version="1.8.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
<PackageReference Include="Swashbuckle.AspNetCore.Filters" Version="7.0.2" />
<PackageReference Include="UAParser" Version="3.1.47" />
</ItemGroup>
<ItemGroup>
<Content Remove="wwwroot\CodeGenTemplate\VueTemplate.txt" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ZR.CodeGenerator\ZR.CodeGenerator.csproj" />
<ProjectReference Include="..\ZR.Service\ZR.Service.csproj" />
<ProjectReference Include="..\ZR.Tasks\ZR.Tasks.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="AspNetCoreRateLimit" Version="4.0.2" />
<PackageReference Include="EPPlus" Version="5.8.6" />
<PackageReference Include="Hei.Captcha" Version="0.3.0" />
<PackageReference Include="IPTools.China" Version="1.6.0" />
<PackageReference Include="CSRedisCore" Version="3.6.9" />
<PackageReference Include="Mapster" Version="7.3.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="5.0.0" NoWarn="NU1605" />
<PackageReference Include="NETCore.Encrypt" Version="2.1.0" />
<PackageReference Include="NLog" Version="4.7.14" />
<PackageReference Include="NLog.Web.AspNetCore" Version="4.14.0" />
<PackageReference Include="Snowflake.Core" Version="2.0.0" />
<PackageReference Include="SqlSugar.IOC" Version="1.8.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
<PackageReference Include="Swashbuckle.AspNetCore.Filters" Version="7.0.2" />
<PackageReference Include="UAParser" Version="3.1.47" />
</ItemGroup>
<ItemGroup>
<Content Update="NLog.config">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ZR.CodeGenerator\ZR.CodeGenerator.csproj" />
<ProjectReference Include="..\ZR.Service\ZR.Service.csproj" />
<ProjectReference Include="..\ZR.Tasks\ZR.Tasks.csproj" />
</ItemGroup>
<ItemGroup>
<None Update="build.bat">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Dockerfile">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="ip2region.db">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="ZRAdmin.xml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<Content Update="NLog.config">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<Folder Include="DataProtection\" />
<Folder Include="wwwroot\export\" />
</ItemGroup>
<ItemGroup>
<None Update="build.bat">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Dockerfile">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="ip2region.db">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="ZRAdmin.xml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<Folder Include="Controllers\Business\" />
<Folder Include="DataProtection\" />
<Folder Include="wwwroot\export\" />
</ItemGroup>
<ItemGroup>
<Service Include="{508349b6-6b84-4df5-91f0-309beebad82d}" />
</ItemGroup>
<ItemGroup>
<Service Include="{508349b6-6b84-4df5-91f0-309beebad82d}" />
</ItemGroup>
</Project>