Tuesday, December 6, 2011

How to update a cookie in asp.net C#?

In my previous post we learn how to retrieve cookie in silverlight, now i am showing how to update cookies value in asp.net C# :) why C# ? hahaha because i love this :)

Here is the code for update cookie
string IpAddress="";
 HttpCookie ck = Request.Cookies["clientIPAdd"];
                if (ck.Value == "undefined" || string.IsNullOrEmpty(ck.Value))
                    ck.Value = IpAddress;

I think you remember about my post Cookie , in this post the cookie created by javascript so may be sometims its returns undefined. So when ever it returns undefined or empty value the above code will update the related (clientIPAdd) cookie value to ""

Cheers :)

No comments:

Post a Comment