//------------------------------------------------------------------------------ // // Copyright (c) Microsoft Corporation. All rights reserved. // //------------------------------------------------------------------------------ namespace System.Web.UI.WebControls { using System; using System.ComponentModel; using System.Data; /// /// Represents a Parameter that gets its value from the application's request parameters. /// [ DefaultProperty("CookieName"), ] public class CookieParameter : Parameter { /// /// Creates an instance of the CookieParameter class. /// public CookieParameter() { } /// /// Creates an instance of the CookieParameter class with the specified parameter name and request field. /// public CookieParameter(string name, string cookieName) : base(name) { CookieName = cookieName; } /// /// Creates an instance of the CookieParameter class with the specified parameter name, database type, and /// request field. /// public CookieParameter(string name, DbType dbType, string cookieName) : base(name, dbType) { CookieName = cookieName; } /// /// Creates an instance of the CookieParameter class with the specified parameter name, type, and request field. /// public CookieParameter(string name, TypeCode type, string cookieName) : base(name, type) { CookieName = cookieName; } /// /// Used to clone a parameter. /// protected CookieParameter(CookieParameter original) : base(original) { CookieName = original.CookieName; ValidateInput = original.ValidateInput; } /// /// The name of the request parameter to get the value from. /// [ DefaultValue(""), WebCategory("Parameter"), WebSysDescription(SR.CookieParameter_CookieName), ] public string CookieName { get { object o = ViewState["CookieName"]; if (o == null) return String.Empty; return (string)o; } set { if (CookieName != value) { ViewState["CookieName"] = value; OnParameterChanged(); } } } /// /// Creates a new CookieParameter that is a copy of this CookieParameter. /// protected override Parameter Clone() { return new CookieParameter(this); } /// /// Returns the updated value of the parameter. /// protected internal override object Evaluate(HttpContext context, Control control) { if (context == null || context.Request == null) { return null; } HttpCookieCollection cookieCollection = ValidateInput ? context.Request.Cookies : context.Request.Unvalidated.Cookies; HttpCookie cookie = cookieCollection[CookieName]; if (cookie == null) { return null; } return cookie.Value; } /// /// Determines whether the parameter's value is being validated or not. /// [ WebCategory("Behavior"), WebSysDescription(SR.Parameter_ValidateInput), DefaultValue(true) ] public bool ValidateInput { get { object o = ViewState["ValidateInput"]; if (o == null) return true; return (bool)o; } set { if (ValidateInput != value) { ViewState["ValidateInput"] = value; OnParameterChanged(); } } } } }