Monday, March 31, 2008

This Blog Has Moved!

This is friendly reminder that if you're looking for new and fresh content from yours truly (Caveman), you should head on over to my new blog at Caveman's blog

Tuesday, March 25, 2008

Replace special characters in XML, using C#

We can use the SecurityElement.Escape method to replace the invalid XML characters in a string with their valid XML equivalent [1].

Namespace: System.Security
Assembly: mscorlib (in mscorlib.dll)

I have used the HttpUtility classes UrlEncode and UrlDecode methods to handle cross-site scripting attacks and this also helped me to get rid of the XmlException - "Data at the root level is invalid".

Reference:
1. MSDN

Friday, March 14, 2008

Cookie Viewer

During the development of a web application that supports cookies, it is almost always a necessity to have the knowledge of what is being persisted in the cookie.

Okay.... what options does one have to achieve this?

hmm..... lets see... well I can think of three ways of doing this:

1. Write a web page application to read all the cookie key/value pairs and display them.
2. Write a windows application to read all the cookie key/value pairs and display them.
3. Open the cookie file manually and go through the content.

I have been there and done that ... I mean during the course of my s/w development activities in the past I have myself implemented all three ways that I mentioned above and yet was not happy with the ease of use.

What if I could find some freeware that does the hard part of fetching all the cookies and enumerating them on a pane that is visually appealing.

Finally !!! I have stumbled on one such freeware utility called IE Cookies Viewer. This utility that displays the details of all cookies that Internet Explorer stores on your computer.



Following are a few things that this utility allows you to do:

1. Sort the cookies list by any column you want, by clicking the column header. A second click sorts the column in descending order.
2. Find a cookie in the list by specifying the name of the Web site.
3. Select and delete the unwanted cookies.
4. Save the cookies to a readable text file.
5. Copy cookie information into the clipboard.
6. Automatically refresh the cookies list when a Web site sends you a cookie.
7. Display the cookies of other users and from other computers.
8. Open the IECookiesView utility directly from Internet Explorer toolbar.
9. Change the content of a cookie !
10. Export your cookies to Netscape/Mozilla cookies file.
11. Block specific Web sites from using cookies through the cookies blocking mechanism of Internet Explorer 6.0.

It can be downloaded at NirSoft. This site has a lot of some cool stuff/utilities that is free for download.

ASP.Net Permanent Cookie vs Temporary Cookie (Update: 03/17/08)

When a cookie is assigned a value without defining the "Expires" property, that cookie would expire as soon as the browser is closed and will be called as a temporary cookie.

A permanent cookie is one where the "Expires" property is defined for that cookie, it will be persisted on the client computer and will expire as per the definition of the "Expires" property.

Internet Explorer on Windows (XP/2000/2003) writes its cookies in the C:\Documents and Settings\[user_name]\Cookies folder.

References:
1. NirSoft