src/EasyFrameWork/Mvc/Authorize/CustomerAuthorizeAttribute.cs
(完整代码) 1KB/* http://www.zkea.net/
* Copyright (c) ZKEASOFT. All rights reserved.
* http://www.zkea.net/licenses */
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.Extensions.DependencyInjection;
namespace Easy.Mvc.Authorize
{
public class CustomerAuthorizeAttribute : AuthorizeAttribute, IActionFilter
{
public const string CustomerAuthenticationScheme = "CustomerAuthenticationScheme";
public CustomerAuthorizeAttribute()
{
this.AuthenticationSchemes = CustomerAuthenticationScheme;
}
public void OnActionExecuted(ActionExecutedContext context)
{
}
public void OnActionExecuting(ActionExecutingContext context)
{
if (context.HttpContext.User.Identity.IsAuthenticated && context.HttpContext.RequestServices.GetService<IApplicationContext>().CurrentCustomer == null)
{
context.HttpContext.SignOutAsync(AuthenticationSchemes).Wait();
context.Result = new NotFoundResult();
}
}
}
}
24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明
AI 解读 AI
登录后可用,每次 10 算力,解读结果公开显示在下面。
还没有人解读过这个文件。