Merge branch 'NETCore-3.0'
# Conflicts: # Directory.Build.props # src/admin/Bootstrap.Admin/Bootstrap.Admin.csproj # src/admin/Bootstrap.Admin/Startup.cs
This commit is contained in:
commit
e7a4eb5899
|
@ -26,4 +26,4 @@
|
|||
<Copy Condition="'$(OS)' == 'UNIX'" DestinationFolder="$(TargetDir)" SourceFiles="$(MSBuildThisFileDirectory)src/admin/keys/Longbow.lic" SkipUnchangedFiles="true" />
|
||||
</Target>
|
||||
|
||||
</Project>
|
||||
</Project>
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp2.2</TargetFramework>
|
||||
<TargetFramework>netcoreapp3.0</TargetFramework>
|
||||
<AddRazorSupportForMvc>true</AddRazorSupportForMvc>
|
||||
</PropertyGroup>
|
||||
|
||||
|
||||
<PropertyGroup>
|
||||
<DocumentationFile>$(MSBuildProjectName).xml</DocumentationFile>
|
||||
<DockerDefaultTargetOS>Windows</DockerDefaultTargetOS>
|
||||
|
@ -13,12 +14,12 @@
|
|||
<PackageReference Include="Bootstrap.Security.DataAccess" Version="2.2.21" />
|
||||
<PackageReference Include="Bootstrap.Security.Mvc" Version="3.0.0" />
|
||||
<PackageReference Include="Longbow.Configuration" Version="2.2.7" />
|
||||
<PackageReference Include="Longbow.Logging" Version="3.0.0" />
|
||||
<PackageReference Include="Longbow.Tasks" Version="2.2.23" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.App" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning" Version="3.1.6" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.0.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.SignalR.Protocols.NewtonsoftJson" Version="3.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="3.0.0" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
|
||||
<PackageReference Include="Sentry.AspNetCore" Version="1.2.0" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="4.0.1" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
|
@ -108,7 +108,7 @@ namespace Bootstrap.Admin.Controllers
|
|||
/// </summary>
|
||||
/// <param name="host"></param>
|
||||
/// <returns></returns>
|
||||
public ActionResult Profiles([FromServices]IHostingEnvironment host) => View(new ProfilesModel(this, host));
|
||||
public ActionResult Profiles([FromServices]IWebHostEnvironment host) => View(new ProfilesModel(this, host));
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
using Bootstrap.DataAccess;
|
||||
using Bootstrap.DataAccess;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
@ -24,7 +24,7 @@ namespace Bootstrap.Admin.Controllers.Api
|
|||
/// <returns></returns>
|
||||
[HttpPost("{id}")]
|
||||
[ButtonAuthorize(Url = "~/Admin/Profiles", Auth = "saveIcon")]
|
||||
public JsonResult Post(string id, [FromServices]IHostingEnvironment env, [FromForm]DeleteFileCollection files)
|
||||
public JsonResult Post(string id, [FromServices]IWebHostEnvironment env, [FromForm]DeleteFileCollection files)
|
||||
{
|
||||
if (!id.Equals("Delete", StringComparison.OrdinalIgnoreCase)) return new JsonResult(new object());
|
||||
|
||||
|
@ -72,7 +72,7 @@ namespace Bootstrap.Admin.Controllers.Api
|
|||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[ButtonAuthorize(Url = "~/Admin/Profiles", Auth = "saveIcon")]
|
||||
public async Task<JsonResult> Post([FromServices]IHostingEnvironment env, IFormCollection files)
|
||||
public async Task<JsonResult> Post([FromServices]IWebHostEnvironment env, IFormCollection files)
|
||||
{
|
||||
var previewUrl = string.Empty;
|
||||
long fileSize = 0;
|
||||
|
@ -128,4 +128,4 @@ namespace Bootstrap.Admin.Controllers.Api
|
|||
return ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,35 +1,33 @@
|
|||
using Microsoft.AspNetCore.Authorization;
|
||||
using Swashbuckle.AspNetCore.Swagger;
|
||||
using Swashbuckle.AspNetCore.SwaggerGen;
|
||||
using System.Collections.Generic;
|
||||
using Operation = Swashbuckle.AspNetCore.Swagger.Operation;
|
||||
//using Microsoft.AspNetCore.Authorization;
|
||||
//using Microsoft.OpenApi.Models;
|
||||
//using Swashbuckle.AspNetCore.SwaggerGen;
|
||||
//using System.Collections.Generic;
|
||||
|
||||
namespace Bootstrap.Admin
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public class HttpHeaderOperation : IOperationFilter
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="operation"></param>
|
||||
/// <param name="context"></param>
|
||||
public void Apply(Operation operation, OperationFilterContext context)
|
||||
{
|
||||
if (operation.Parameters == null) operation.Parameters = new List<IParameter>();
|
||||
//namespace Bootstrap.Admin
|
||||
//{
|
||||
// /// <summary>
|
||||
// ///
|
||||
// /// </summary>
|
||||
// public class HttpHeaderOperation : IOperationFilter
|
||||
// {
|
||||
// /// <summary>
|
||||
// ///
|
||||
// /// </summary>
|
||||
// /// <param name="operation"></param>
|
||||
// /// <param name="context"></param>
|
||||
// public void Apply(OpenApiOperation operation, OperationFilterContext context)
|
||||
// {
|
||||
// if (operation.Parameters == null) operation.Parameters = new List<OpenApiParameter>();
|
||||
|
||||
if (context.MethodInfo.GetCustomAttributes(typeof(AllowAnonymousAttribute), true).Length == 0)
|
||||
{
|
||||
operation.Parameters.Add(new NonBodyParameter()
|
||||
{
|
||||
Name = "Authorization", //添加Authorization头部参数
|
||||
In = "header",
|
||||
Type = "string",
|
||||
Required = false
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// if (context.MethodInfo.GetCustomAttributes(typeof(AllowAnonymousAttribute), true).Length == 0)
|
||||
// {
|
||||
// operation.Parameters.Add(new OpenApiParameter()
|
||||
// {
|
||||
// Name = "Authorization", //添加Authorization头部参数
|
||||
// In = ParameterLocation.Header,
|
||||
// Required = false
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
|
|
@ -30,7 +30,7 @@ namespace Bootstrap.Admin.Models
|
|||
/// </summary>
|
||||
/// <param name="host"></param>
|
||||
/// <param name="controller"></param>
|
||||
public ProfilesModel(ControllerBase controller, IHostingEnvironment host) : base(controller)
|
||||
public ProfilesModel(ControllerBase controller, IWebHostEnvironment host) : base(controller)
|
||||
{
|
||||
if (host != null)
|
||||
{
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
using Microsoft.AspNetCore;
|
||||
using Bootstrap.DataAccess;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace Bootstrap.Admin
|
||||
{
|
||||
|
@ -14,14 +16,15 @@ namespace Bootstrap.Admin
|
|||
/// <param name="args"></param>
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
CreateWebHostBuilder(args).Build().Run();
|
||||
CreateHostBuilder(args).Build().Run();
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="args"></param>
|
||||
/// <returns></returns>
|
||||
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
|
||||
WebHost.CreateDefaultBuilder(args).UseSentry().UseStartup<Startup>();
|
||||
public static IHostBuilder CreateHostBuilder(string[] args) =>
|
||||
Host.CreateDefaultBuilder(args)
|
||||
.ConfigureWebHostDefaults(builder => builder.UseStartup<Startup>());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,20 +1,17 @@
|
|||
using Bootstrap.DataAccess;
|
||||
using Longbow.Web;
|
||||
using Longbow.Web.SignalR;
|
||||
using Microsoft.AspNetCore.Authentication.Cookies;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.HttpOverrides;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.Versioning;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Serialization;
|
||||
using System;
|
||||
using System.Text.Encodings.Web;
|
||||
using System.Text.Unicode;
|
||||
|
||||
namespace Bootstrap.Admin
|
||||
{
|
||||
|
@ -44,47 +41,51 @@ namespace Bootstrap.Admin
|
|||
/// <param name="services"></param>
|
||||
public void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
services.AddSingleton(HtmlEncoder.Create(UnicodeRanges.All));
|
||||
//services.AddSingleton(HtmlEncoder.Create(UnicodeRanges.All));
|
||||
services.Configure<CookiePolicyOptions>(options =>
|
||||
{
|
||||
// This lambda determines whether user consent for non-essential cookies is needed for a given request.
|
||||
options.CheckConsentNeeded = context => true;
|
||||
options.MinimumSameSitePolicy = SameSiteMode.None;
|
||||
});
|
||||
services.AddLogging(logging => logging.AddFileLogger().AddDBLogger(ExceptionsHelper.Log));
|
||||
services.AddCors();
|
||||
services.AddLogging(builder => builder.AddFileLogger().AddDBLogger(ExceptionsHelper.Log));
|
||||
services.AddConfigurationManager();
|
||||
services.AddCacheManager();
|
||||
services.AddDbAdapter();
|
||||
services.AddIPLocator(DictHelper.ConfigIPLocator);
|
||||
services.AddOnlineUsers();
|
||||
services.AddSignalR().AddJsonProtocalDefault();
|
||||
services.AddSignalRExceptionFilterHandler<SignalRHub>((client, ex) => client.SendMessageBody(ex).ConfigureAwait(false));
|
||||
services.AddSignalR().AddNewtonsoftJsonProtocol(op =>
|
||||
{
|
||||
op.PayloadSerializerSettings.ContractResolver = new DefaultContractResolver();
|
||||
op.PayloadSerializerSettings.DateFormatString = "yyyy-MM-dd HH:mm:ss";
|
||||
});
|
||||
services.AddSignalRExceptionFilterHandler<SignalRHub>(async (client, ex) => await client.SendMessageBody(ex).ConfigureAwait(false));
|
||||
services.AddResponseCompression();
|
||||
services.AddBootstrapAdminAuthentication().AddGitee(OAuthHelper.Configure).AddGitHub(OAuthHelper.Configure);
|
||||
services.AddSwagger();
|
||||
services.AddAuthorization(options => options.DefaultPolicy = new AuthorizationPolicyBuilder().RequireBootstrapAdminAuthorizate().Build());
|
||||
//services.AddSwagger();
|
||||
services.AddButtonAuthorization(MenuHelper.AuthorizateButtons);
|
||||
services.AddBootstrapAdminBackgroundTask();
|
||||
services.AddHttpClient<GiteeHttpClient>();
|
||||
services.AddAdminHealthChecks();
|
||||
services.AddMvc(options =>
|
||||
services.AddControllersWithViews(options =>
|
||||
{
|
||||
options.Filters.Add<BootstrapAdminAuthorizeFilter>();
|
||||
options.Filters.Add<ExceptionFilter>();
|
||||
options.Filters.Add<SignalRExceptionFilter<SignalRHub>>();
|
||||
}).AddJsonOptions(options =>
|
||||
}).AddNewtonsoftJson(op =>
|
||||
{
|
||||
options.SerializerSettings.ContractResolver = new DefaultContractResolver();
|
||||
options.SerializerSettings.DateFormatString = "yyyy-MM-dd HH:mm:ss";
|
||||
JsonConvert.DefaultSettings = () => options.SerializerSettings;
|
||||
}).SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
|
||||
services.AddApiVersioning(option =>
|
||||
{
|
||||
option.DefaultApiVersion = new ApiVersion(1, 0);
|
||||
option.ReportApiVersions = true;
|
||||
option.AssumeDefaultVersionWhenUnspecified = true;
|
||||
option.ApiVersionReader = ApiVersionReader.Combine(new HeaderApiVersionReader("api-version"), new QueryStringApiVersionReader("api-version"));
|
||||
op.SerializerSettings.ContractResolver = new DefaultContractResolver();
|
||||
op.SerializerSettings.DateFormatString = "yyyy-MM-dd HH:mm:ss";
|
||||
JsonConvert.DefaultSettings = () => op.SerializerSettings;
|
||||
});
|
||||
//services.AddApiVersioning(option =>
|
||||
//{
|
||||
// option.DefaultApiVersion = new ApiVersion(1, 0);
|
||||
// option.ReportApiVersions = true;
|
||||
// option.AssumeDefaultVersionWhenUnspecified = true;
|
||||
// option.ApiVersionReader = ApiVersionReader.Combine(new HeaderApiVersionReader("api-version"), new QueryStringApiVersionReader("api-version"));
|
||||
//});
|
||||
}
|
||||
|
||||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
||||
|
@ -93,7 +94,7 @@ namespace Bootstrap.Admin
|
|||
/// </summary>
|
||||
/// <param name="app"></param>
|
||||
/// <param name="env"></param>
|
||||
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
|
||||
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
||||
{
|
||||
app.UseForwardedHeaders(new ForwardedHeadersOptions() { ForwardedHeaders = ForwardedHeaders.All });
|
||||
if (env.IsDevelopment())
|
||||
|
@ -110,18 +111,21 @@ namespace Bootstrap.Admin
|
|||
app.UseHttpsRedirection();
|
||||
app.UseResponseCompression();
|
||||
app.UseStaticFiles();
|
||||
app.UseRouting();
|
||||
app.UseAuthentication();
|
||||
app.UseAuthorization();
|
||||
app.UseBootstrapAdminAuthorization(RoleHelper.RetrievesByUserName, RoleHelper.RetrievesByUrl, AppHelper.RetrievesByUserName);
|
||||
app.UseBootstrapHealthChecks();
|
||||
app.UseOnlineUsers(TraceHelper.Filter, TraceHelper.Save);
|
||||
app.UseCacheManager();
|
||||
app.UseSignalR(routes =>
|
||||
//app.UseSwagger(Configuration["SwaggerPathBase"].TrimEnd('/'));
|
||||
app.UseEndpoints(endpoints =>
|
||||
{
|
||||
routes.MapHub<SignalRHub>("/NotiHub");
|
||||
routes.MapHub<TaskLogHub>("/TaskLogHub");
|
||||
endpoints.MapHub<SignalRHub>("/NotiHub");
|
||||
endpoints.MapHub<TaskLogHub>("/TaskLogHub");
|
||||
endpoints.MapHealthChecks("/healths");
|
||||
endpoints.MapDefaultControllerRoute().RequireAuthorization();
|
||||
});
|
||||
app.UseSwagger(Configuration["SwaggerPathBase"].TrimEnd('/'));
|
||||
app.UseMvcWithDefaultRoute();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,58 +1,59 @@
|
|||
using Microsoft.AspNetCore.Authentication;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Swashbuckle.AspNetCore.Swagger;
|
||||
using System;
|
||||
using System.IO;
|
||||
//using Microsoft.AspNetCore.Authentication;
|
||||
//using Microsoft.AspNetCore.Builder;
|
||||
//using Microsoft.Extensions.DependencyInjection;
|
||||
//using Microsoft.OpenApi.Models;
|
||||
//using Swashbuckle.AspNetCore.Swagger;
|
||||
//using System;
|
||||
//using System.IO;
|
||||
|
||||
namespace Bootstrap.Admin
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
internal static class SwaggerExtensions
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="app"></param>
|
||||
/// <param name="pathBase"></param>
|
||||
public static void UseSwagger(this IApplicationBuilder app, string pathBase)
|
||||
{
|
||||
app.UseWhen(context => context.Request.Path.StartsWithSegments("/swagger"), builder =>
|
||||
{
|
||||
builder.Use(async (context, next) =>
|
||||
{
|
||||
if (!context.User.Identity.IsAuthenticated) await context.ChallengeAsync();
|
||||
else await next();
|
||||
});
|
||||
});
|
||||
app.UseSwagger();
|
||||
app.UseSwaggerUI(c =>
|
||||
{
|
||||
c.SwaggerEndpoint($"{pathBase}/swagger/v1/swagger.json", "BootstrapAdmin API V1");
|
||||
});
|
||||
}
|
||||
//namespace Bootstrap.Admin
|
||||
//{
|
||||
// /// <summary>
|
||||
// ///
|
||||
// /// </summary>
|
||||
// internal static class SwaggerExtensions
|
||||
// {
|
||||
// /// <summary>
|
||||
// ///
|
||||
// /// </summary>
|
||||
// /// <param name="app"></param>
|
||||
// /// <param name="pathBase"></param>
|
||||
// public static void UseSwagger(this IApplicationBuilder app, string pathBase)
|
||||
// {
|
||||
// app.UseWhen(context => context.Request.Path.StartsWithSegments("/swagger"), builder =>
|
||||
// {
|
||||
// builder.Use(async (context, next) =>
|
||||
// {
|
||||
// if (!context.User.Identity.IsAuthenticated) await context.ChallengeAsync();
|
||||
// else await next();
|
||||
// });
|
||||
// });
|
||||
// app.UseSwagger();
|
||||
// app.UseSwaggerUI(c =>
|
||||
// {
|
||||
// c.SwaggerEndpoint($"{pathBase}/swagger/v1/swagger.json", "BootstrapAdmin API V1");
|
||||
// });
|
||||
// }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="services"></param>
|
||||
public static void AddSwagger(this IServiceCollection services)
|
||||
{
|
||||
services.AddSwaggerGen(options =>
|
||||
{
|
||||
options.SwaggerDoc("v1", new Info
|
||||
{
|
||||
Version = "v1",
|
||||
Title = "BootstrapAdmin API"
|
||||
});
|
||||
// /// <summary>
|
||||
// ///
|
||||
// /// </summary>
|
||||
// /// <param name="services"></param>
|
||||
// public static void AddSwagger(this IServiceCollection services)
|
||||
// {
|
||||
// services.AddSwaggerGen(options =>
|
||||
// {
|
||||
// options.SwaggerDoc("v1", new OpenApiInfo
|
||||
// {
|
||||
// Version = "v1",
|
||||
// Title = "BootstrapAdmin API"
|
||||
// });
|
||||
|
||||
//Set the comments path for the swagger json and ui.
|
||||
var xmlPath = Path.Combine(AppContext.BaseDirectory, "Bootstrap.Admin.xml");
|
||||
options.IncludeXmlComments(xmlPath);
|
||||
options.OperationFilter<HttpHeaderOperation>(); // 添加httpHeader参数
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
// //Set the comments path for the swagger json and ui.
|
||||
// var xmlPath = Path.Combine(AppContext.BaseDirectory, "Bootstrap.Admin.xml");
|
||||
// options.IncludeXmlComments(xmlPath);
|
||||
// options.OperationFilter<HttpHeaderOperation>(); // 添加httpHeader参数
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
|
|
@ -11,7 +11,6 @@
|
|||
<PackageReference Include="Longbow.GiteeAuth" Version="2.2.0" />
|
||||
<PackageReference Include="Longbow.GitHubAuth" Version="2.2.0" />
|
||||
<PackageReference Include="Longbow.OAuth" Version="2.2.2" />
|
||||
<PackageReference Include="Longbow.Logging" Version="2.2.13" />
|
||||
<PackageReference Include="Longbow.PetaPoco" Version="1.0.2" />
|
||||
<PackageReference Include="Longbow.Security.Cryptography" Version="1.3.0" />
|
||||
<PackageReference Include="Longbow.Tasks" Version="2.2.23" />
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp2.2</TargetFramework>
|
||||
<TargetFramework>netcoreapp3.0</TargetFramework>
|
||||
<IsPackable>false</IsPackable>
|
||||
<DebugType>full</DebugType>
|
||||
</PropertyGroup>
|
||||
|
@ -11,7 +11,6 @@
|
|||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.AspNetCore.App" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="2.2.0" />
|
||||
<PackageReference Include="Microsoft.Data.Sqlite" Version="2.2.6" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.2.0" />
|
||||
|
|
Loading…
Reference in New Issue