增加swagger 权限校验
parent
18612c18a7
commit
2465b1a28f
|
|
@ -1109,7 +1109,7 @@
|
||||||
登录管理【无权限】
|
登录管理【无权限】
|
||||||
</summary>
|
</summary>
|
||||||
</member>
|
</member>
|
||||||
<member name="M:New_College.Controllers.LoginController.#ctor(New_College.IServices.ISysUserInfoServices,New_College.IServices.IUserRoleServices,New_College.IServices.IRoleServices,New_College.AuthHelper.PermissionRequirement,New_College.IServices.IRoleModulePermissionServices)">
|
<member name="M:New_College.Controllers.LoginController.#ctor(New_College.IServices.ISysUserInfoServices,New_College.IServices.IUserRoleServices,New_College.IServices.IRoleServices,New_College.AuthHelper.PermissionRequirement,New_College.IServices.IRoleModulePermissionServices,Microsoft.AspNetCore.Http.IHttpContextAccessor)">
|
||||||
<summary>
|
<summary>
|
||||||
构造函数注入
|
构造函数注入
|
||||||
</summary>
|
</summary>
|
||||||
|
|
|
||||||
|
|
@ -50,6 +50,7 @@ namespace New_College
|
||||||
{
|
{
|
||||||
// 以下code可能与文章中不一样,对代码做了封装,具体查看右侧 Extensions 文件夹.
|
// 以下code可能与文章中不一样,对代码做了封装,具体查看右侧 Extensions 文件夹.
|
||||||
services.AddSingleton<IRedisCacheManager, RedisCacheManager>();
|
services.AddSingleton<IRedisCacheManager, RedisCacheManager>();
|
||||||
|
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
|
||||||
services.AddSingleton(new Appsettings(Configuration));
|
services.AddSingleton(new Appsettings(Configuration));
|
||||||
services.AddSingleton(new LogLock(Env.ContentRootPath));
|
services.AddSingleton(new LogLock(Env.ContentRootPath));
|
||||||
|
|
||||||
|
|
@ -113,7 +114,7 @@ namespace New_College
|
||||||
services.Configure<KestrelServerOptions>(x => x.AllowSynchronousIO = true)
|
services.Configure<KestrelServerOptions>(x => x.AllowSynchronousIO = true)
|
||||||
.Configure<IISServerOptions>(x => x.AllowSynchronousIO = true);
|
.Configure<IISServerOptions>(x => x.AllowSynchronousIO = true);
|
||||||
|
|
||||||
// services.AddSession();
|
services.AddSession();
|
||||||
services.AddControllers(o =>
|
services.AddControllers(o =>
|
||||||
{
|
{
|
||||||
// 全局异常过滤
|
// 全局异常过滤
|
||||||
|
|
@ -164,6 +165,7 @@ namespace New_College
|
||||||
// 注意在Program.CreateHostBuilder,添加Autofac服务工厂
|
// 注意在Program.CreateHostBuilder,添加Autofac服务工厂
|
||||||
public void ConfigureContainer(ContainerBuilder builder)
|
public void ConfigureContainer(ContainerBuilder builder)
|
||||||
{
|
{
|
||||||
|
|
||||||
builder.RegisterModule(new AutofacModuleRegister());
|
builder.RegisterModule(new AutofacModuleRegister());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -193,7 +195,7 @@ namespace New_College
|
||||||
// 强制实施 HTTPS 在 ASP.NET Core,配合 app.UseHttpsRedirection
|
// 强制实施 HTTPS 在 ASP.NET Core,配合 app.UseHttpsRedirection
|
||||||
//app.UseHsts();
|
//app.UseHsts();
|
||||||
}
|
}
|
||||||
// app.UseSession();
|
app.UseSession();
|
||||||
app.UseSwaggerAuthorized();
|
app.UseSwaggerAuthorized();
|
||||||
// 封装Swagger展示
|
// 封装Swagger展示
|
||||||
app.UseSwaggerMildd(() => GetType().GetTypeInfo().Assembly.GetManifestResourceStream("New_College.Api.index.html"));
|
app.UseSwaggerMildd(() => GetType().GetTypeInfo().Assembly.GetManifestResourceStream("New_College.Api.index.html"));
|
||||||
|
|
|
||||||
|
|
@ -22,18 +22,18 @@ namespace New_College.Common
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
await next.Invoke(context);
|
//await next.Invoke(context);
|
||||||
return;
|
//return;
|
||||||
|
|
||||||
// 判断权限是否正确
|
// 判断权限是否正确
|
||||||
//if (IsAuthorized(context))
|
if (IsAuthorized(context))
|
||||||
//{
|
{
|
||||||
// await next.Invoke(context);
|
await next.Invoke(context);
|
||||||
// return;
|
return;
|
||||||
//}
|
}
|
||||||
|
|
||||||
//// 无权限,跳转swagger登录页
|
// 无权限,跳转swagger登录页
|
||||||
//context.RedirectSwaggerLogin();
|
context.RedirectSwaggerLogin();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue