Microsoft Silverlight is an Internet technology similar to Flash. A web developer can use images, videos and animation to make a web page more interactive with the user. The Silverlight application is fully integrated with Visual Studio, so you can use C# to develop Silverlight interactivity. One part of web page coding is the creation and addition of cookies. You can delete a cookie using only a few lines of code.
1. Open your Silverlight project. Double-click the page used to delete the cookie. Right-click the form and choose “Code View.”
2. Initiate the cookie class and assign it to the cookie you want to delete. Initiating the class allows you to use its methods and properties. The code below assigns a cookie variable to a cookie with the “userId” name:
string old_Cookie = HtmlPage.Document.GetProperty(“userId”) as String;
3. Create an expiration date. Cookies are removed when they reach the expiration date. If you set the expiration date for a date that has passed, you cancel the cookie. The following code creates a date variable:
DateTime expire = DateTime.Now – 1;
4. Set the cookie to expire. Once this statement is run, the cookie is removed from the user’s machine:
5. Save the file and press the F5 key to test the settings. The F5 key runs the application in debug mode, so you can test your new cookie settings.