Cookies in ASP.Net

Cookies can also be set in ASP.NET , to set cookies in asp.net you can proceed as follows

    public string GetCookies()
    {
        string myLocation = Request.Cookies[“WHLocation”].Value;
        return myLocation;
    }


    public void SetCookies(string WHLocation)
    {


        HttpCookie WHCookie = new HttpCookie(“WHCookie”);
        WHCookie.Values.Add(“WHLocation”, WHLocation);
        WHCookie.Expires= DateTime.Now.AddDays(1);


        Response.Cookies.Add(WHCookie);


    }

Get Set Cookies in Java Script

Cookies can be get via java script and an be set via java script.  you can get set cookies in javascript by method given below

         function setCookie(c_name, value, exdays) {
            var exdate = new Date();
            exdate.setDate(exdate.getDate() + exdays);
            var c_value = escape(value) + ((exdays == null) ? “” : “; expires=” + exdate.toUTCString());
            document.cookie = c_name + “=” + c_value;
        }




        function getCookie(c_name) {
            var i, x, y, ARRcookies = document.cookie.split(“;”);
            for (i = 0; i < ARRcookies.length; i++) {
                x = ARRcookies[i].substr(0, ARRcookies[i].indexOf(“=”));
                y = ARRcookies[i].substr(ARRcookies[i].indexOf(“=”) + 1);
                x = x.replace(/^\s+|\s+$/g, “”);
                if (x == c_name) {
                    return unescape(y);
                }
            }
        }