Justin Cooney

Web Development Tips and Examples

  • Generating GUIDS in ASP.NET
    Generating GUIDS in ASP.NET

    GUIDs are useful tools for .NET developers and Windows developers in general. If you need a unique value for your code, then a GUID (Globally Unique Identifier) is one of the best ways to go.

    One thing to keep in mind when working with GUIDs is that there is always a chance of getting a collision/duplication between GUIDs, especially if you are working with large numbers of them.

    Here is an example 128 bit GUID:

    2b3ed884-f3a7-447b-84cd-62e9221e6548

    As you can see, based on the number of alphanumeric digits in the example above, the likelihood of getting a duplicate GUID is extremely low. However when using a GUID, there is always a chance that duplicates will appear, especially as the sample size increases, or as the method of generating the GUID changes.

    It is because of this that I would suggest using them with small in-memory lists, or to uniquely identify programs in the registry, but I would be leery of using GUIDs as primary keys in a large & permanent SQL Server table (I’m certain there are people who will disagree with me on this point, but I stand firm in my belief that this is bad coding practice).

    (more…)

  • November 6 2012: After the crisis with their domain hijacking, there are some amazing accounts coming out about what happened. This article on TechCrunch tells quite an incredible story.

    October 26 2012: @Diigo on Twitter has announced that they are back in control of the Diigo.com domain as of about 5:00ET.

    The domain update should have propagated through the Internet by now so Diigo.com is safe to access now. Diigo states that the total outage time was 48 hours.

    It remains to be seen if people’s PCs have been infected by possible malware hosted on the hijacked sites. I certainly hope this is not the case.

    October 25 2012 – Warning: do not browse to Diigo.com. The site has been domain hijacked.

    The Web is going crazy with viruses and hack attacks these days. It seems like every day there is news of a new compromise.

    Today I was surprised when I tried browsing to Diigo.com (a great social bookmarking site that I like to use) only to find myself redirected to site I do not recognize that has bizarre popups. It looks like the site has been compromised.

    Happily Diigo has been keeping its user base updated on Twitter via @diigo .

    It seems user data has not been lost and all of one’s social bookmarks are still in place. Diigo is working with its domain registrar Yahoo hosting to correct the hijacking, but progress is slow. Based on people’s reports on Twitter it seems the hijack happened sometime yesterday (22 hours ago as of 3:00 ET Sept 25 2012) and Yahoo hosting has still not corrected things. In the meantime @Diigo on Twitter is advising users to point their browsers to Diigo.net which is still operational.

    Wikipedia has a short entry explaining the Diigo domain problem that is worth checking out.

    When I checked the URL for the hijacker’s site, it comes up with a 0 trust rating, which is definitely not good. I wonder if there is a chance of malware or a virus attack coming from the site. Some people on Twitter are reporting that their Antivirus software is showing warnings of Trojans.

    My Antivirus software did not report a problem, but I will need to run diagnostics on my machine to try to clear up any garbage that might have found its way on, and I also plan to change all of my passwords just to be safe.

    This sort of thing is always annoying when it happens, but it is definitely a wake up call to anyone developing sites for the Web. It’s a bit like the wild-west out there and there is danger lurking around every corner if you are not careful.

    Links

  • InvalidCastException
    InvalidCastException was unhandled by user code

    If you are working with XML data types in your .NET and SQL Server code, then you will most likely encounter this error message at some point.

    Specifically, this error is related to improperly passing an XML value as a SQLParameter to your database.

    Since most of the work one does with XML in .NET is done using the XmlDocument object, it is certainly surprising when Visual Studio complains when one tries to save the XML object as an XmlDocument to the database (say to a stored procedure or directly to a database table).

    The bottom line is that you must adjust your  XmlDocument object  to a format compatible with the SqlDbType.XML accepted by your SqlParameters.

    There are a few ways that you can use to pass your XML object to your database:

    (more…)