当前位置: 代码迷 >> 综合 >> .NetCore 登陆过滤器
  详细解决方案

.NetCore 登陆过滤器

热度:7   发布时间:2023-12-01 12:42:04.0

是他是他就是它:
就是一句话解决:

filterContext.Result = new RedirectResult("/User/MyLogin");

过滤器代码

public class LoginAuthAttribute: ActionFilterAttribute
{
    public override void OnActionExecuting(ActionExecutingContext filterContext){
    var uId = filterContext.HttpContext.Session.GetString("uId");if (uId == null){
    //仅有这句话跳转时登陆界面会显示在iframe框架中//filterContext.HttpContext.Response.Redirect("/User/MyLogin");filterContext.Result = new RedirectResult("/User/MyLogin");//filterContext.HttpContext.Response.StatusCode = 404 ;//filterContext.HttpContext.Response.();//base.OnActionExecuting(filterContext);}}}
  相关解决方案