Scott Selby
Scott Selby

Reputation: 9580

adding/setting a cookie vb.net

I know how to add / set cookies in VB.Net , usually I check if it is null ( or Nothing in VB) if it is nothing I set a new cookie , if it is not then I set the value of the previous cookie. My question is there any thing wrong , or any down side to just adding a cookie every time like this:

HttpContext.Current.Response.Cookies.Add(New HttpCookie("Lat", dt(0)(1).ToString().Trim()))

I'm hoping that this will just override the previous Cookie("Lat") if it exists , and set a new one if it doesn't , if this works it will really make my code a lot shorter and make things easier. I don't see why this wouldn't work - but every tutorial and example online normally checks if it exists first.

Upvotes: 2

Views: 2861

Answers (1)

KV Prajapati
KV Prajapati

Reputation: 94653

If you want to add (duplicate) cookie into the collection then use Add method and want to update an existing cookie then call the Cookies.Set method. (Reference MSDN)

Upvotes: 1

Related Questions