ASP.NET MVC - CustomeAuthorize filter action using an external website for loggin in the user

前端 未结 3 1663
轮回少年
轮回少年 2020-12-16 05:36

I have a CustomeAuthorize action filter that forwards the user to signin page if user is not authenticated. I apply this filter to actions or controllers.

[         


        
相关标签:
3条回答
  • 2020-12-16 06:06

    Use the RedirectResult similar to how you were using the RedirectToRouteResult before to replace the result in the filter context.

    filterContext.Result = new RedirectResult("http://externalSite.com/login?returnUrl=" + filterContext.HttpContext.Request.RawUrl );
    
    0 讨论(0)
  • 2020-12-16 06:11

    Let me see if I understand - you have an iFrame, and executing an action within this iFrame. You want to redirect to a parent page, not within that iFrame?

    If so, just use Redirect(url) in your action.

    0 讨论(0)
  • 2020-12-16 06:16

    You can add a judgement by jQuery on the login page.

    $(function () {
            if (window != top) {
                top.location.href = location.href;
            }
        });   
    

    OR

    edit 'filterContext.Result' in action 'OnActionExecuting'

    filterContext.Result = new ContentResult() { Content = "<script>top.window.location.href='/user/Login'</script>" };
    
    0 讨论(0)
提交回复
热议问题