Search code examples
cookiesvisual-studio-2005datetime-generation

How to set cookie expiration date in asp.net


Good Day to All,

I am working with a small code, where I cant get my right hand part correctly

Response.Cookie("MyCookie").Expires=DateTime.FromString("2011-10-1");

Above cookie codes were used in my company's old project, I am updating the code and could not find a property named FromString in DateTime. Can anybody tell me an alternative to get desired result ?


Solution

  • To get a DateTime from a string, you would use DateTime.Parse

    DateTime.Parse("2011-10-1")