C#/.NET MVC2016.02.04 14:44

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; }

        }


    }

저작자 표시 비영리 동일 조건 변경 허락
신고

Posted by jangjeonghun

티스토리 툴바