티스토리 뷰

public class AuthorizationAttribute : FilterAttribute, IAuthorizationFilter    

    {


        void IAuthorizationFilter.OnAuthorization(AuthorizationContext filterContext)

        {

            HttpCookie cookie = filterContext.RequestContext.HttpContext.Request.Cookies.Get("AccessToken");

            Controller controller = filterContext.Controller as Controller;


            if (cookie == null || string.IsNullOrEmpty(WebConfig.SessionUserID))

            {                

                controller.HttpContext.Response.Redirect(redirectUrl);

                

                //filterContext.Result = new RedirectToRouteResult( new RouteValueDictionary { 

                //    { "controller", "Home" }

                //    , { "action", "Index" } 

                //});

            }


            if (!this.dataEncryption.PBKDF2Compare(cookie.Value, this.dataEncryption.PBKDF2(this.dataEncryption.SHA1Decrypt(WebConfig.SessionUserID, WebConfig.Salt), WebConfig.Salt, int.Parse(WebConfig.Iteration))))

            {

                controller.HttpContext.Response.Redirect(redirectUrl);

            }

        }


        private DataEncryption dataEncryption = new DataEncryption();

        private string redirectUrl = WebConfig.SignInUrl;

        public string RedirectUrl

        {

            get { return redirectUrl; }

            set { redirectUrl = value; }

        }


    }

728x90
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2024/04   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30
글 보관함