diff --git a/Biwen.Settings.TestWebUI/Program.cs b/Biwen.Settings.TestWebUI/Program.cs index 9922d362..8cc87330 100644 --- a/Biwen.Settings.TestWebUI/Program.cs +++ b/Biwen.Settings.TestWebUI/Program.cs @@ -4,9 +4,11 @@ using Biwen.Settings.Encryption; using Biwen.Settings.TestWebUI.Data; using Microsoft.EntityFrameworkCore; +using Microsoft.AspNetCore.HttpLogging; var builder = WebApplication.CreateBuilder(args); + // Add services to the container. builder.Services.AddRazorPages(); @@ -23,6 +25,12 @@ options.UseSqlite("Data Source=BiwenSettings.db"); }); +builder.Services.AddHttpLogging(options => +{ + options.LoggingFields = HttpLoggingFields.All; + options.CombineLogs = true; +}); + //配置garnet client builder.Services.Configure(options => @@ -101,7 +109,12 @@ var app = builder.Build(); // Configure the HTTP request pipeline. -if (!app.Environment.IsDevelopment()) +if (app.Environment.IsDevelopment()) +{ + app.UseHttpLogging(); + app.UseDeveloperExceptionPage(); +} +else { app.UseExceptionHandler("/Error"); } @@ -113,10 +126,11 @@ app.UseStaticFiles(); -app.UseRouting(); - +app.UseAuthentication(); app.UseAuthorization(); +app.UseRouting(); + app.MapRazorPages(); app.UseBiwenSettings(mapNotifyEndpoint: true, builder: builder => diff --git a/Biwen.Settings.TestWebUI/appsettings.Development.json b/Biwen.Settings.TestWebUI/appsettings.Development.json index 770d3e93..623e6853 100644 --- a/Biwen.Settings.TestWebUI/appsettings.Development.json +++ b/Biwen.Settings.TestWebUI/appsettings.Development.json @@ -3,7 +3,7 @@ "Logging": { "LogLevel": { "Default": "Information", - "Microsoft.AspNetCore": "Warning" + "Microsoft.AspNetCore": "Information" } } } diff --git a/Biwen.Settings/Biwen.Settings.http b/Biwen.Settings/Biwen.Settings.http new file mode 100644 index 00000000..43c6c307 --- /dev/null +++ b/Biwen.Settings/Biwen.Settings.http @@ -0,0 +1,19 @@ +@Biwen.Settings_HostAddress = http://localhost:5150 + +POST {{Biwen.Settings_HostAddress}}/biwensetting/api/set/Biwen.Settings.TestWebUI.GithubSetting +Accept: application/json +Content-Type: application/json-patch+json +{ + "UserName" : "vipwan", + "Token":"234567" +} + +### + +GET {{Biwen.Settings_HostAddress}}/biwensetting/api/all + +### + +GET {{Biwen.Settings_HostAddress}}/biwensetting/api/get/Biwen.Settings.TestWebUI.GithubSetting + +### diff --git a/Biwen.Settings/Mvc/ValidDtoFilter.cs b/Biwen.Settings/Mvc/ValidDtoFilter.cs index 8a6a3133..c6c39539 100644 --- a/Biwen.Settings/Mvc/ValidDtoFilter.cs +++ b/Biwen.Settings/Mvc/ValidDtoFilter.cs @@ -1,4 +1,5 @@ using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Routing; using System.Dynamic; namespace Biwen.Settings.Mvc @@ -10,7 +11,8 @@ internal class ValidDtoFilter : IEndpointFilter { public async ValueTask InvokeAsync(EndpointFilterInvocationContext context, EndpointFilterDelegate next) { - var id = context.Arguments[3]!.ToString(); //context.HttpContext.GetRouteValue("id") as string; + var id = context.HttpContext.GetRouteData().Values["id"] as string; + if (string.IsNullOrEmpty(id)) return Results.NotFound(); var type = ASS.InAllRequiredAssemblies.FirstOrDefault(x => x.FullName == id); if (type == null) return Results.NotFound(); @@ -50,8 +52,9 @@ internal class ValidDtoFilter : IEndpointFilter //赋值 prop.SetValue(setting, value); } - var option = (context.Arguments[1] as IOptions)!.Value; - if (option.AutoFluentValidationOption.Enable) + + var option = context.HttpContext.RequestServices.GetRequiredService(typeof(IOptions)) as IOptions; + if (option!.Value.AutoFluentValidationOption.Enable) { //继承至ValidationSettingBase的情况 if (type.BaseType!.IsConstructedGenericType && type.BaseType!.GenericTypeArguments.Any(x => x == type)) @@ -79,13 +82,9 @@ internal class ValidDtoFilter : IEndpointFilter //存在验证器的情况 var validator = context.HttpContext!.RequestServices.GetService(typeof(IValidator<>).MakeGenericType(type)); - if (validator != null) + if (validator is not null && Valid(validator) is (false, var errors)) { - var (Succesed, Errors) = Valid(validator); - if (!Succesed) - { - return Results.ValidationProblem(Errors!); - } + return Results.ValidationProblem(errors!); } } return await next(context); diff --git a/Version.Props b/Version.Props index 418917aa..ad031a26 100644 --- a/Version.Props +++ b/Version.Props @@ -1,7 +1,7 @@ - 2.2.6.1 + 2.2.6.2 提供对IConfiguration和IOptions的集成支持 2.2.0 2.2.0