Bypass Forms Authentication auto redirect to login, How to?

后端 未结 5 1424
臣服心动
臣服心动 2021-02-09 19:37

I\'m writing an app using asp.net-mvc deploying to iis6. I\'m using forms authentication. Usually when a user tries to access a resource without proper authorization I want them

5条回答
  •  南方客
    南方客 (楼主)
    2021-02-09 20:24

    Did you write your own FormsAuth attribute for the action? If so, in the OnActionExecuting method, you get passed the FilterExecutingContext. You can use this to pass back the 401 code.

    public class FormsAuth : ActionFilterAttribute
    {
        public override void OnActionExecuting(FilterExecutingContext filterContext)
        {
            filterContext.HttpContext.Response.StatusCode = 401;
            filterContext.Cancel = true;
        }
    }
    

    This should work. I am not sure if you wrote the FormsAuth attribute or if you got it from somewhere else.

提交回复
热议问题