2

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.

1
  • Use Set method instead of Add. Reference MSDN Commented Oct 10, 2012 at 15:21

1 Answer 1

1

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)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.