Adding WERD Cookie Expiration

The default WERD aspx code sets a cookie which expires when the users session is over. This is normally when the user closes his browser connection. If you would like to add an expiration date so that once the user has passed the WERD challenge question, he is good for say a year from now it is very simple. In this example, I will add an option to the web.config that reads a value in the config section, checks to see if it is an integer and then adds that number of days to the cookie set for WERD. 1. In the web.config file of your WERD site, add the following config section with your other WERD config settings: 2. Next, in the C# code where your WERD challenge is (in this example it is in the default.aspx which is included with WERD), search for the word "cookie". It will look something like this: Response.Cookies[WerdCookie].Value = This part is in the rblWords_SelectedIndexChanged method, which is what is fire when the correct WERD challenge is selected. You can add a section prior to that which checks to see if the config setting called WerdExpirationDays exists, if it does then set the cookie to the number of days specified in the setting you created. try { string xdays = ConfigurationManager.AppSettings["WerdExpirationDays"].ToString(); if (xdays != "") { try { int xset = Convert.ToInt32(xdays); Response.Cookies[WerdCookie].Expires = DateTime.Now.AddDays(xset); } catch { } } } catch { } That is basically all you need. Now, when the WERD cookie is set, the user will have a year before they will be prompted for another WERD challenge. This is of course unless you change the cookie. :)