locked
MVC cookie question RRS feed

  • Question

  • User1143124722 posted

    Hi Guys, 

    I now have an application that sends an email from a Text box input. I want this email to contain a generated link that when the users click the link, it creates a cookie in their browser which will allow them access to the website and will stay persistent through sessions.

    I hope this helps

    Thursday, July 28, 2016 1:44 PM

Answers

  • User-821857111 posted

    It can be any value that you want to store, including your email address if that's what your application requires.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, July 29, 2016 7:02 PM

All replies

  • User-821857111 posted

    You can create a cookie in MVC like this:

    Response.Cookies["YourCookie"].Value = some_value'
    Response.Cookies["YourCookie"].Expires = DateTime.Now.AddYears(100); 

    Note that cookies belong to the browser, so if the user visits using a different browser or machine, the cookie won't be there.

    Thursday, July 28, 2016 9:52 PM
  • User1143124722 posted
    Hi Mike, Thank you for the reply, I was wondering in the Value = some_Value section would this be my email? 

    Response.Cookies["YourCookie"].Value = some_value' Response.Cookies["YourCookie"].Expires = DateTime.Now.AddYears(100);

    Friday, July 29, 2016 9:18 AM
  • User-821857111 posted

    It can be any value that you want to store, including your email address if that's what your application requires.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, July 29, 2016 7:02 PM