public static RequestValidationToken Create(HttpContextBase context)
        {
            RequestValidationToken token = new RequestValidationToken();

            token._creationDate = DateTime.Now;
            token._signature    = GenerateRequestSignature(context);

            return(token);
        }
        public bool IsValid(RequestValidationToken obj)
        {
            if (Object.ReferenceEquals(obj, null))
            {
                return(false);
            }

            if (!String.Equals(_value, obj._value, StringComparison.Ordinal))
            {
                return(false);
            }

            return(String.Equals(_signature, obj._signature, StringComparison.Ordinal));
        }
        public static RequestValidationToken Create(string serializedTokenData)
        {
            RequestValidationToken token     = new RequestValidationToken();
            IStateFormatter        formatter = TokenPersister.CreateFormatter();

            try
            {
                State state = (State)formatter.Deserialize(serializedTokenData);

                token._value        = state.Value;
                token._signature    = state.Signature;
                token._creationDate = state.CreationDate;
            }
            catch (Exception exception)
            {
                throw Error.RequestValidationError(exception);
            }
            return(token);
        }
        public void OnAuthorization(AuthorizationContext context)
        {
            Precondition.Require(context, () => Error.ArgumentNull("context"));
            string value = context.HttpContext.Request.Parameters.Form.GetValue <string>(FieldName);

            if (String.IsNullOrEmpty(value))
            {
                throw Error.RequestValidationError();
            }

            RequestValidationToken current = RequestValidationToken.Create(context.HttpContext, Value);
            RequestValidationToken token   = RequestValidationToken.Create(value);

            if (!token.IsValid(current))
            {
                throw Error.RequestValidationError();
            }

            if (_timeout > 0 && (DateTime.Now - token.CreationDate).TotalMinutes > _timeout)
            {
                throw Error.RequestValidationError();
            }
        }
        public bool IsValid(RequestValidationToken obj)
        {
            if (Object.ReferenceEquals(obj, null))
                return false;

            if (!String.Equals(_value, obj._value, StringComparison.Ordinal))
                return false;

            return String.Equals(_signature, obj._signature, StringComparison.Ordinal);
        }
        public static RequestValidationToken Create(string serializedTokenData)
        {
            RequestValidationToken token = new RequestValidationToken();
            IStateFormatter formatter = TokenPersister.CreateFormatter();
            try
            {
                State state = (State)formatter.Deserialize(serializedTokenData);

                token._value = state.Value;
                token._signature = state.Signature;
                token._creationDate = state.CreationDate;
            }
            catch (Exception exception)
            {
                throw Error.RequestValidationError(exception);
            }
            return token;
        }
        public static RequestValidationToken Create(HttpContextBase context)
        {
            RequestValidationToken token = new RequestValidationToken();

            token._creationDate = DateTime.Now;
            token._signature = GenerateRequestSignature(context);

            return token;
        }