Monday, March 19, 2012

Read and Write Cookies C#

using System;
using System.Web.UI;

/// 
/// Cookies
/// 
public class clsCookies{

    public string GetCookie(Page page, string cookieName, string defaultValue) {
        try {
            if (page.Request.Cookies[cookieName] != null)
            {
                return (page.Request.Cookies[cookieName].Value);
            }
            else {
                return (defaultValue);
            }
        }
        catch {
            return (defaultValue);
        }
    }

    public void SetCookie(Page page, string cookieName,string cookieValue) {
        page.Response.Cookies[cookieName].Value = cookieValue;
    }
}

Please visit: www.TyroDeveloper.com

Please Click on +1

No comments:

Post a Comment