<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>

<channel>
	<title>Dot Net Yuppie</title>
	<atom:link href="http://dotnetyuppie.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://dotnetyuppie.com</link>
	<description>Web design, SQL, and .NET for the young, up-and-coming developer</description>
	<pubDate>Thu, 01 May 2008 04:38:43 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5.1</generator>
	<language>en</language>
			<item>
		<title>Website Review of DoshDosh.com</title>
		<link>http://dotnetyuppie.com/2008/04/30/website-review-of-doshdoshcom/</link>
		<comments>http://dotnetyuppie.com/2008/04/30/website-review-of-doshdoshcom/#comments</comments>
		<pubDate>Thu, 01 May 2008 04:38:43 +0000</pubDate>
		<dc:creator>DotNetYuppie</dc:creator>
		
		<category><![CDATA[Web Design]]></category>

		<category><![CDATA[Website Reviews]]></category>

		<guid isPermaLink="false">http://dotnetyuppie.com/?p=55</guid>
		<description><![CDATA[Maki, the author of an internet marketing and social media blog called Dosh Dosh, recently revamped his website with a completely new design, which received both positive and negative feedback on his blog post announcing the new theme.  Being a long-term subscriber of his website, I would like to provide a review of his [...]]]></description>
			<content:encoded><![CDATA[<p>Maki, the author of an internet marketing and social media blog called <a href="http://doshdosh.com">Dosh Dosh</a>, recently revamped his website with a completely new design, which received both positive and negative feedback on <a href="http://www.doshdosh.com/dosh-dosh-finally-gets-a-new-site-design/">his blog post announcing the new theme</a>.  Being a long-term subscriber of his website, I would like to provide a review of his new theme.  As a developer, I&#8217;ve found that one of the best ways to improve my own skills is to evaluate the skills of others.</p>
<p>If you haven&#8217;t heard of <a href="http://doshdosh.com">DoshDosh.com</a>, I highly encourage you to visit &#8212; he has phenomenal content related to blogging, freelancing, marketing, etc. that would be extremely useful for any web developer.</p>
<p><span id="more-55"></span></p>
<p><strong>Overview</strong><br />
DoshDosh&#8217;s theme was designed to give &#8220;precedence to the content&#8221; &#8212; the design is minimalistic, with a two-column fixed-width (948px) centered layout.  The content takes up almost 2/3rds of the width of the page, and the sidebar allows for two 125&#215;125 ads to be placed side-by-side.</p>
<p><img src="http://dotnetyuppie.com/wp-content/uploads/2008/04/doshdoshthumb.jpg" alt="" title="DoshDosh.com Thumbnail" width="320" height="256" border="0" class="aligncenter size-full wp-image-56" /></p>
<p><strong>Color Scheme</strong><br />
The color scheme is very minimalistic &#8212; it is essentially black, white, and gray with a hint of <span style="color: #FFF; background-color: #993333;">#993333</span> (scarlet red).  Because of the simple color scheme, the sidebar&#8217;s advertisements bring extra attention to themselves due to their color variety.  The links are all colored in the same #993333 red color, which brings a good consistency to the layout.</p>
<p><img src="http://dotnetyuppie.com/wp-content/uploads/2008/04/doshdoshpalette.png" alt="" title="Dosh Dosh Color Palette" width="200" height="30" class="aligncenter size-full wp-image-57" style="border: 1px solid #000;" /></p>
<p><strong>Logo</strong><br />
David Airey, the designer of the logo, has an <a href="http://www.davidairey.com/logo-design-for-dosh-dosh/">excellent post regarding the logo&#8217;s design from conception to implementation</a>.  David mentions that the final selection of a logo was between the current logo (&#8221;H&#8221;), and logo &#8220;B&#8221;, as seen below.  I would have much rather had the more complex &#8220;B&#8221; logo instead of the current logo.  Additionally, the gray/white/black color scheme for the logo is dreary.  A splash of color would have made the logo much more effective.  On the upside, the current simplistic logo degrades very nicely into favicon.ico.</p>
<p><img src="http://dotnetyuppie.com/wp-content/uploads/2008/04/doshdoshlogos.png" alt="" title="Dosh Dosh Logos by David Airey" width="321" height="143" class="aligncenter size-full wp-image-61" /></p>
<p><strong>Header</strong><br />
The header takes up 55px, which is quite short for a header, but the intention of the new design was to bring focus to the content.  I don&#8217;t mind the header/logo, but I don&#8217;t think it&#8217;s optimal for the design &#8212; it&#8217;s almost <em>too simplistic and too monochrome</em>.  </p>
<p><img src="http://dotnetyuppie.com/wp-content/uploads/2008/04/doshdoshheader.png" alt="" title="Dosh Dosh Header" width="226" height="91" class="aligncenter size-full wp-image-59" border="0" /></p>
<p>The worst design faux pas committed by the new design is the fact that there is no tagline, description, or explanation of what doshdosh.com is within the header.  The first sentence of the website&#8217;s &#8220;about&#8221; page describes doshdosh.com as, &#8220;Dosh Dosh is a blog offering internet marketing and blogging tips, alongside social media strategies&#8221;.  The downside to his minimalist header is that it doesn&#8217;t describe his website at all &#8212; a simple sentence in the header could improve his new visitor retention.</p>
<p><strong>Header Navigation</strong><br />
I&#8217;m very happy to see the use of color with the navigation menu, but I&#8217;ve never been a fan of keeping the navigation highlighted respective to the current page.  For example, if you go to the &#8220;About&#8221; page, the &#8220;About&#8221; navigation icon will appear red by default.  While it adds some needed color, it isn&#8217;t entirely accurate.  If you navigate to any specific article, the &#8220;Home&#8221; navigation item still appears red, despite the fact that you are not at the &#8220;Home&#8221; page.</p>
<p><img src="http://dotnetyuppie.com/wp-content/uploads/2008/04/doshdoshnavigation.png" alt="" title="Dosh Dosh Navigation" width="356" height="91" class="aligncenter size-full wp-image-60" /></p>
<p><strong>SEO</strong><br />
To the writer&#8217;s credit, all the &lt;TITLE&gt; tags are optimized for search engines.  Even on his home page, which is rare for blogs to do, he puts a description of his blog ahead of the title of his blog (&#8221;Internet Marketing and Social Media: Dosh Dosh&#8221;).  Because of his domain name, he will easily score well on search engines for the words &#8220;dosh dosh&#8221;, so it isn&#8217;t necessary to have a title tag that only displays the name of the blog.  By putting a description of his site first, he has attained a #2 rank for the term <a href="http://www.google.com/search?q=internet+marketing+social+media">&#8220;internet marking social media&#8221;</a>.</p>
<p>Based on the HTML comments hidden within the design, it appears that the <a href="http://wordpress.org/extend/plugins/all-in-one-seo-pack/">All in One SEO Pack</a> is installed, but it isn&#8217;t being used to its fullest extent.  By not manually specifying a description and series of keywords for each post, he is getting stuck with poor-SEO terms.  For example, in <a href="http://www.doshdosh.com/dosh-dosh-finally-gets-a-new-site-design/">his post announcing the new theme</a>, his keywords are &#8220;general stuff&#8221; and the description is made up of the first thirty words of his post.  I realize that there is some debate regarding the lack of beneficial effect to well-formed &lt;META&gt; SEO tags, but it can&#8217;t hurt to spend an extra minute to hammer out a few keywords about your post.</p>
<p><strong>Sidebar</strong><br />
I&#8217;m very impressed with the sidebar design.  Its width is enough to allow for two ads per row, but it&#8217;s not so wide that it receives more attention than the content.  All too often, web designers get greedy and overtake their websites with gaudy, animated ads that distract from the beauty of their design.</p>
<p>I fully understand the need to make money through advertisements, and the more money the better, but eight ads at the top of the sidebar promotes ad blindness and doesn&#8217;t make any one of the advertisements unique.  A design of four advertisements (at twice the advertising cost) would both decrease ad blindness and allow for each individual ad to stand out more.</p>
<p>I don&#8217;t like the placement of the rest of the items within the sidebar.  Below the advertisements include: &#8220;Recent Posts&#8221;, &#8220;Categories&#8221;, &#8220;Top 10 Most Viewed Articles Today&#8221;, &#8220;Google Custom Search&#8221;, &#8220;My Twitter Updates&#8221;, &#8220;My Digg Submissions&#8221;, and &#8220;My StumbleUpon Profile&#8221;.  I&#8217;ll address the google custom search below, but I feel like &#8220;Recent Posts&#8221; and &#8220;Top 10 Most Viewed Articles Today&#8221; would be better placed within the footer, rather than in the sidebar.  I could be wrong, but it seems like a reader is more likely to notice both sections if they were placed in the footer because they get lost in the clutter of the sidebar.  Conversely, the three social networking website feeds could be placed in the footer instead to reduce the sidebar clutter.</p>
<p><strong>Google Custom Search</strong><br />
I can&#8217;t imagine the search box gets used very often because it&#8217;s knee-deep in sidebar clutter.  I understand that you can make Adsense money by using Google&#8217;s search feature, but Wordpress has excellent search functionality that trumps Google&#8217;s ability to display blog posts.  Again, I understand that some sacrifices can and should be made in the name of website revenue, but you could place your own, small Adsense advertisements at the top of a search page if you wanted while still retaining a Wordpress-driven search page.</p>
<p><img src="http://dotnetyuppie.com/wp-content/uploads/2008/04/googlecustomsearch.jpg" alt="" title="Dosh Dosh's positioning of google custom search" width="192" height="440" class="aligncenter size-full wp-image-62" /></p>
<p>Aside from the fact that the search functionality uses Google, I can&#8217;t understand the reason for its placement.  For the most part, a visitor, who wants to search for a term on your website, is probably going to hope to find the search box somewhere in the header or at the top of the sidebar.  Again, it seems that revenue has trumped good design practices &#8212; while the search box should probably go at the very top of the sidebar, it has been pushed down by the RSS/e-mail subscription sign-up (which increases traffic and subsequent revenue) and by the advertisements.</p>
<p><strong>Accessibility</strong><br />
Because of the minimalist design, the page degrades very nicely when CSS is not enabled.  The sidebar&#8217;s text is placed after the content, which makes it easier for visitors with screen readers to get directly to the content.  Normally I would suggest an invisible &#8220;Jump to Content&#8221; link, but because he has four navigation links before the content, I don&#8217;t think it&#8217;s necessary.</p>
<p><strong>Conclusion</strong><br />
Dosh Dosh&#8217;s new design is clean and minimalistic, specifically focusing on content over fancy web design.  The design is almost too simplistic, particularly the logo and color scheme, but the biggest fault is the cluttered sidebar.  I appreciate the desire to have a minimalistic design, and the designer accomplished this goal, but as a frequent reader, I would have liked to see a fancier CSS or artwork built into the design.</p>
]]></content:encoded>
			<wfw:commentRss>http://dotnetyuppie.com/2008/04/30/website-review-of-doshdoshcom/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Enabling SSL (HTTPS) for IIS in Windows XP</title>
		<link>http://dotnetyuppie.com/2008/04/26/enabling-ssl-https-for-iis-in-windows-xp/</link>
		<comments>http://dotnetyuppie.com/2008/04/26/enabling-ssl-https-for-iis-in-windows-xp/#comments</comments>
		<pubDate>Sun, 27 Apr 2008 04:26:19 +0000</pubDate>
		<dc:creator>DotNetYuppie</dc:creator>
		
		<category><![CDATA[Windows/IIS]]></category>

		<guid isPermaLink="false">http://dotnetyuppie.com/?p=53</guid>
		<description><![CDATA[A reader recently asked about enabling SSL for a web application, but without the hassle of applying for a verified certificate.  This article will outline the process to enable HTTPS on a Windows XP machine, but the process of creating a self-signed certificate is applicable to just about any version of Windows.
What is a [...]]]></description>
			<content:encoded><![CDATA[<p>A reader recently asked about enabling SSL for a web application, but without the hassle of applying for a verified certificate.  This article will outline the process to enable HTTPS on a Windows XP machine, but the process of creating a self-signed certificate is applicable to just about any version of Windows.</p>
<p><strong>What is a certificate?</strong><br />
A certificate is a file that contains a set of instructions, which are read by a client computer, outlining the process of properly encrypting and decrypting data.  The certificate is unique to a website, and ensures the security of the client&#8217;s data to and from a server.</p>
<p><span id="more-53"></span></p>
<p>To increase security, these certificates are often signed by a third party, called a <a href="http://en.wikipedia.org/wiki/Certificate_authority">certificate authority</a>, who verifies that the server is who they say they are.  Unfortunately, the process of obtaining a third-party verification costs money and takes time.</p>
<p><strong>Why self-sign?</strong><br />
If you don&#8217;t want to pay money to have an official SSL certificate, but you still want the security of an encrypted HTTP session, then you can self-sign the certificate.  Self-signing simply means that instead of having a third-party verify the integrity of the server/certificate, you&#8217;re doing it yourself.  A client computer won&#8217;t recognize your self-signature as being reliable, but at least you&#8217;ll have encrypted data.</p>
<p>Obviously if you&#8217;re running a full-scale, professional website you&#8217;ll want to get a third-party verification, but if you&#8217;re running small-scale web applications off a personal computer for your own use, then there&#8217;s no reason to spend money for verification.  Unfortunately, Windows XP doesn&#8217;t make it easy to self-sign your certificate to enable SSL on your local machine.</p>
<p><strong>How to create your own SSL certificate</strong></p>
<ol>
<li><strong>Download and install OpenSSL</strong>.  The OpenSSL project doesn&#8217;t distribute compiled binary files, but Shining Light Productions offers a Windows installation (currently &#8220;Win32 OpenSSL v0.9.8g Light&#8221;), which you can <a href="http://www.slproweb.com/products/Win32OpenSSL.html">download here (1MB)</a>.  Its default installation is to c:\OpenSSL.</li>
<li><strong>Open the Web Server Certificate Wizard</strong>.  Open up IIS 5.1 (your results may vary in other versions), right click &#8216;Default Web Site&#8217; and select &#8216;Properties.  Click on the &#8216;Directory Security&#8217; tab, and then the &#8216;Server Certificate&#8230;&#8217; button.  The wizard should appear.
<p><img src="http://dotnetyuppie.com/wp-content/uploads/2008/04/ssl1.jpg" alt="" title="Default Web Site Properties window" width="473" height="460" class="aligncenter size-full wp-image-54" />
</li>
<li><strong>Create a new certificate request</strong>.  Once in the wizard, select &#8220;Create a new certificate&#8221;, and &#8220;Prepare the request now, but send it later&#8221;.  You can fill out the remainder of the certificate request as you see fit &#8212; for the most part, leave things as their default values, but change the name of the website/organization/organizational unit/common name/country/region/etc. to whatever you prefer.  When you get to the end of the wizard, it will ask you where you want to save the certificate request (default c:\certreq.txt).  Save it to wherever you want, but keep the certreq.txt filename so the rest of the instructions work.</li>
<li><strong>Create the security certificate</strong>.  Open up a command-line window, and type out the following commands.  Note that this assumes that your OpenSSL directory is c:\OpenSSL and your certificate request is c:\certreq.txt
<p><strong>cd c:\OpenSSL\bin</strong></p>
<p><strong>openssl genrsa -des3 -out CA.key 1024</strong><br />
(Note that you will be asked for a pass phrase &#8212; you&#8217;ll have to make one up that is 4-511 character is length)</p>
<p><strong>openssl req -new -key CA.key -x509 -days 1095 -out CA.cer</strong><br />
(Note that you will have to enter the pass phrase from the previous step.  In addition, it will ask you the same questions that were asked from IIS &#8212; fill in the same answers or hit enter for default responses)</p>
<p><strong>openssl x509 -req -days 730 -in c:\certreq.txt -CA CA.cer -CAkey CA.key -CAcreateserial -out SelfSignedCert.cer</strong><br />
(Note that you will have to enter the pass phrase from the previous two steps again)</p>
</li>
<li>If all goes well, you will have a file at <strong>C:\OpenSSL\bin\SelfSignedCert.cer</strong> that is your self-signed certificate.</li>
<li>Open the Web Server Certificate Wizard again (from step 2).  You&#8217;ll note that you have a new option, called &#8220;Process the pending request and install the certificate&#8221;.  Select this option and target the path/filename to C:\OpenSSL\bin\SelfSignedCert.cer.</li>
<li>Now, you can enable SSL for any application on your server by right-clicking it, going to &#8220;Properties&#8221;, the &#8220;Directory Security&#8221; tab, and the &#8220;Edit&#8230;&#8221; button at the bottom.</li>
<li>To enable SSL, select &#8220;Require secure channel (SSL)&#8221; and hit OK.
<p><img src="http://dotnetyuppie.com/wp-content/uploads/2008/04/ssl2.jpg" alt="" title="Secure Communications window" width="410" height="386" class="aligncenter size-full wp-image-51" />
</li>
</ol>
<p><strong>A note about the warning to clients</strong><br />
Whenever a browser goes to a self-signed HTTPS site, they will receive a notification that the security of the site cannot be validated.  This warning makes sense because you signed the certificate, and you are not one of the few certificate authorities.  Regardless, be sure to &#8220;accept&#8221; the warning and the site&#8217;s certificate &#8212; the web session will still be securely encrypted.</p>
<p><img src="http://dotnetyuppie.com/wp-content/uploads/2008/04/ssl3.jpg" alt="" title="Unknown Authority Certificate error window" width="500" height="354" class="aligncenter size-full wp-image-52" /></p>
<p><strong>Conclusion</strong><br />
Once Windows Server 2003 came out, Microsoft realized how essential it was to be able to SSL on the fly, so they made it much, much easier to self-sign certificates.  For those still using XP, however, you&#8217;re stuck using OpenSSL to self-sign certificates.</p>
<p>Keep in mind that this process is really only meant for personal applications &#8212; users don&#8217;t like to get unfriendly &#8220;unknown certificate&#8221; messages when they visit your site.</p>
]]></content:encoded>
			<wfw:commentRss>http://dotnetyuppie.com/2008/04/26/enabling-ssl-https-for-iis-in-windows-xp/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Handling and Recording Exceptions in .NET</title>
		<link>http://dotnetyuppie.com/2008/04/22/handling-and-recording-exceptions-in-net/</link>
		<comments>http://dotnetyuppie.com/2008/04/22/handling-and-recording-exceptions-in-net/#comments</comments>
		<pubDate>Wed, 23 Apr 2008 03:35:55 +0000</pubDate>
		<dc:creator>DotNetYuppie</dc:creator>
		
		<category><![CDATA[.NET]]></category>

		<category><![CDATA[Facade]]></category>

		<category><![CDATA[Snippets]]></category>

		<guid isPermaLink="false">http://dotnetyuppie.com/?p=13</guid>
		<description><![CDATA[There&#8217;s nothing more amateur than displaying a big, yellow unhandled exception page for a .NET application.  Professionally done ASP.NET websites need adequate error handling and recording.  It&#8217;s not enough to catch exceptions and display a friendly error page &#8212; you need to record any unhandled errors so that they can be fixed.


Proper Error [...]]]></description>
			<content:encoded><![CDATA[<p>There&#8217;s nothing more amateur than displaying a big, yellow unhandled exception page for a .NET application.  Professionally done ASP.NET websites <em>need</em> adequate error handling <strong>and recording</strong>.  It&#8217;s not enough to catch exceptions and display a friendly error page &#8212; you need to record any unhandled errors so that they can be fixed.</p>
<p><img src="http://dotnetyuppie.com/wp-content/uploads/2008/04/unhandledexception.jpg" alt="" title="Unhandled Exception" width="400" height="244" class="alignright size-full wp-image-47" /></p>
<p><span id="more-13"></span></p>
<p><strong>Proper Error Handling - Step 1</strong><br />
The first step to handling errors is to Try/Catch them before they occur.  If you&#8217;re performing some action that has a high probability of throwing an error (e.g. anything relating to a call to a database or read/write to a file), you should enclose your logic in a Try/Catch statement.</p>
<p>Keep in mind, however, that throwing exceptions is bad.  Generally speaking, exception handling takes up a lot of resources and is a very slow process.  If exceptions are being thrown, it&#8217;s probable that you didn&#8217;t do enough error checking ahead of time to prevent the exception from being thrown.  If you record your exceptions (as I&#8217;ll show you how to do), you can retrospectively look back and see what type of preemptive error checking you should have done to prevent the exception from being thrown in the first place.</p>
<pre name="code" class="vb">

Public Sub ErrorProneCode()

    'Inadequate error checking here

    Try
        'Make call to database or file I/O that
        ' throws a nasty exception
    Catch ex As Exception
        'Catch the exception -- either display a message
        ' to the user that an error occurred, or redirect
        ' the user to a standard &quot;error&quot; page

        'Don't forget to record the exception so that
        ' you can investigate at a later time
    Finally
        'Also, don't forget to clean up (destroy)
        ' any(objects) that might cause a leak
    End Try

End Sub
</pre>
<p><strong>Proper Error Handling - Step 2</strong><br />
Sometimes, developers don&#8217;t have enough foresight to Try/Catch/Finally every single error-prone line of code, and exceptions go unhandled.  Unfortunately, if you haven&#8217;t set up a standardized error page, users are rudely presented with a big, yellow Microsoft error page that means absolutely nothing to the end-user.  To add insult to injury, Microsoft&#8217;s error page does not record the exception that occurred, which means you (the developer) won&#8217;t hear about it unless the end-user complains.</p>
<p>For the instances when you don&#8217;t have an exception wrapped up in a Try/Catch, you need to add a Global.asax.  To do so, open your project, &#8220;Add New Item&#8221;, and then select &#8220;Global Application Class&#8221;.  The default name is Global.asax.</p>
<p>Within Global.asax, you can specify what happens when the <strong>Application_Error</strong> event fires.  Application_Error occurs when an unhandled exception occurs and is not caught by a Try/Catch.  When you add Global.asax, it adds several event handlers automatically &#8212; add your code to the Application_Error event, similar to this:</p>
<pre name="code" class="vb">

Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
    ' Code that runs when an unhandled error occurs
    ' The exception was not caught with a Try/Catch

    'Get the last exception that occurred
    ' (which sent us to Application_Error)
    Dim ex As Exception = Server.GetLastError

    'Record the error somewhere so that you can prevent this
    ' from happening in the future.  RecordException() is a method
    ' that you need to write yourself.  I have included psuedocode
    ' for it below
    RecordException(ex, SomeURL)

    'Response.Redirect() the user to a generalized &quot;Error&quot; page
End Sub
</pre>
<p><strong>Recording Your Error</strong><br />
Regardless of whether you had a handled or unhandled exception, you still need to record it so that you can take steps to prevent the exception from occurring in the future.  Typically, errors can be recorded by inserting them into a database.  Of course, if your exception is originating because you can&#8217;t connect to the database, then you won&#8217;t be able to record any exceptions.</p>
<p>The variables that you record are important so that you can track down problems.  I prefer to have any session or user data (e.g. UserID, SessionID, username, etc.), the date/time, the stack trace, the inner stack trace, the exception message, and the URL that originated the exception.  Your data preference may vary, but the most important section is the stack trace.</p>
<p>The following pseudocode is an example of how to record an exception.  This method would be called by either the Catch section of a Try/Catch or Global.asax&#8217;s Application_Error:</p>
<pre name="code" class="vb">

Public Sub RecordException(ByVal ex As Exception, ByVal OriginatingURL As String)

    Dim ParamList As New ArrayList

    ParamList.Add(New Data.SqlClient.SqlParameter( _
        &quot;Username&quot;, Session(&quot;Username&quot;)))
    ParamList.Add(New Data.SqlClient.SqlParameter( _
        &quot;DateOfError&quot;, Now))
    ParamList.Add(New Data.SqlClient.SqlParameter( _
        &quot;StackTrace&quot;, ex.StackTrace))
    ParamList.Add(New Data.SqlClient.SqlParameter( _
        &quot;InnerStackTrace&quot;, ex.InnerException.StackTrace))
    ParamList.Add(New Data.SqlClient.SqlParameter( _
        &quot;ExceptionMessage&quot;, ex.Message))
    ParamList.Add(New Data.SqlClient.SqlParameter( _
        &quot;ExceptionMessage&quot;, OriginatingURL))

    'Open connection to SQL database and insert
    ' the exception data into a table

End Sub
</pre>
<p><strong>Conclusion</strong><br />
There are many ways to catch and record exceptions, but there are two basic principles.  First, you need to present the end-user with some sort of notification that notifies them that something weird is going on, and that you&#8217;ve been notified about it.  Microsoft&#8217;s default error page is not an adequate error page.  Second, you need to record any exceptions that were not expected.  I prefer to record my exceptions in an SQL database, and then use the database as a &#8216;to do&#8217; list when I&#8217;m tracking down bugs.  Regardless of your method for recording exceptions, it needs to be done so that the end-user doesn&#8217;t have to manually report bugs to you.</p>
]]></content:encoded>
			<wfw:commentRss>http://dotnetyuppie.com/2008/04/22/handling-and-recording-exceptions-in-net/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Please Preload Your CSS Images</title>
		<link>http://dotnetyuppie.com/2008/04/20/please-preload-your-css-images/</link>
		<comments>http://dotnetyuppie.com/2008/04/20/please-preload-your-css-images/#comments</comments>
		<pubDate>Mon, 21 Apr 2008 03:36:42 +0000</pubDate>
		<dc:creator>DotNetYuppie</dc:creator>
		
		<category><![CDATA[CSS]]></category>

		<guid isPermaLink="false">http://dotnetyuppie.com/?p=41</guid>
		<description><![CDATA[Please, for your own good, preload your CSS images.
It&#8217;s becoming more popular to use the :hover pseudo-class to toggle a background-image in a &#60;div&#62; block to simulate various visual effects, but many developers are making the mistake of not preloading the :hover image.  It looks unprofessional when a user hovers over an image and [...]]]></description>
			<content:encoded><![CDATA[<p>Please, for your own good, preload your CSS images.</p>
<p>It&#8217;s becoming more popular to use the :hover pseudo-class to toggle a background-image in a &lt;div&gt; block to simulate various visual effects, but many developers are making the mistake of not preloading the :hover image.  It looks unprofessional when a user hovers over an image and has to wait for a new background-image to download and display.</p>
<p><img src="http://dotnetyuppie.com/wp-content/uploads/2008/04/cssbackgroundhover.gif" alt="" title="The Wrong Way to :Hover" width="275" height="63" class="aligncenter size-full wp-image-45" /><br />
As you can see above, there is a small, awkward delay, which isn&#8217;t always so small, that occurs when a :hover background-image is not properly preloaded.</p>
<p><span id="more-41"></span></p>
<p><strong>How To Preload Your Own Images</strong><br />
There are various ways to preload images, but the most efficient and popular way is to use CSS and a sprite, combined image to accomplish the appearance of a preload.</p>
<ol>
<li><strong>Create a single image file with both the normal and the :hover background images.</strong>  I have included an example, called Example.png, below:<br />
<img src="http://dotnetyuppie.com/wp-content/uploads/2008/04/example.png" alt="" title="ExampleButtonHover" width="191" height="105" class="aligncenter size-medium wp-image-44" style="border: 1px solid #000" /></li>
<li><strong>Specify the image dimensions of the first background-image.</strong>  The first button&#8217;s dimensions start at {0,0} and end at {191,52}, after which the second image button begins.  When you specify your image CSS, you need to constrain the background image using the following code &#8212; this will only display the top button in the image file:
<pre name="code" class="css">

#SomeBackgroundImage {
	background: url('Example.png') 0px 0px no-repeat;
	width: 191px;
	height: 52px;
}
</pre>
</li>
<li><strong>Specify the image dimensions for the :hover background</strong><br />
Now that you&#8217;ve set up the initial image, you need to set up the dimensions for when the user&#8217;s mouse hovers over the image.  Once the image hovers, you want the background position to change so that you only see the bottom portion of the image (and exclude the top portion).  All we&#8217;re really doing is telling CSS that our background image starts 53 pixels below where it normally would.  This is achieved by the following code:</p>
<pre name="code" class="css">

#SomeBackgroundImage:hover {
	background: url('Example.png') 0px -53px no-repeat;
	width: 191px;
	height: 52px;
}
</pre>
</li>
</ol>
<p><strong>Why is this method so much better?</strong><br />
Many developers make the honest mistake of creating two separate image files &#8212; like Example.png and ExampleHover.png.  CSS does <strong>not</strong> preload any images &#8212; :hover background-images are not loaded until the pseudo-class is called (i.e. when the user initiates a mouse hover).  This lack of preloading creates the awkward delay between the mouse hovering over an object and CSS displaying a new background-image.</p>
<p>In the example above, a single image file contains both forms of the toggled object, which actually creates two beneficial effects.  First, our :hover image is preloaded because it is part of the original background-image &#8212; CSS only has to move the location of the background image position.  Second, it&#8217;s more efficient to load one larger image than to load two smaller images because there is a performance penalty each time the browser has to make a new HTTP request to a server.  The fewer requests, the better.</p>
]]></content:encoded>
			<wfw:commentRss>http://dotnetyuppie.com/2008/04/20/please-preload-your-css-images/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Serializable MailMessage Class</title>
		<link>http://dotnetyuppie.com/2008/04/02/serializable-mailmessage-class/</link>
		<comments>http://dotnetyuppie.com/2008/04/02/serializable-mailmessage-class/#comments</comments>
		<pubDate>Thu, 03 Apr 2008 04:29:38 +0000</pubDate>
		<dc:creator>DotNetYuppie</dc:creator>
		
		<category><![CDATA[Serialization]]></category>

		<category><![CDATA[Snippets]]></category>

		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://dotnetyuppie.com/2008/04/02/serializable-mailmessage-class/</guid>
		<description><![CDATA[In response to my article on Custom Binary Serialization in .NET, a visitor asked me for a specific example of a custom serialization class of .NET&#8217;s MailMessage class.
As I mentioned in the article, I struggled with the MailMessage and MailAddress class because they cannot be serialized unless you use custom serialization (which can be a [...]]]></description>
			<content:encoded><![CDATA[<p>In response to my article on <a href="http://dotnetyuppie.com/2008/02/17/custom-binary-serialization-in-net">Custom Binary Serialization in .NET</a>, a visitor asked me for a specific example of a custom serialization class of .NET&#8217;s MailMessage class.</p>
<p>As I mentioned in the article, I struggled with the MailMessage and MailAddress class because they cannot be serialized unless you use custom serialization (which can be a big pain because it takes quite a bit of time to create a custom class).  I spent days trying to serialize the MailMessage class using conventional methods, only to find that there is no quick workaround for it other than custom serialization.</p>
<p><span id="more-37"></span></p>
<p><strong>Download My Custom SerialMailMessage Class</strong><br />
If you&#8217;re interested in using my class, you can <a href='http://dotnetyuppie.com/wp-content/uploads/2008/04/serialmailmessage.zip' title='SerialMailMessage'>download the SerialMailMessage code here</a>.</p>
<p>Within the zipped file, you will find the following classes:</p>
<ol>
<li><strong>SerialMailMessageExample </strong>- I have included a simple example that utilizes the SerialMailMessage class.</li>
<li><strong>SerialMailMessage </strong>- A custom serializable class that uses both SerialMailAddress and SerialMailAttachment to create a serializable form of .NET&#8217;s MailMessage class.</li>
<li><strong>Serialization </strong>- A simple class to perform serialization and deserialization of serializable objects</li>
<li><strong>SerialMailAddress </strong>- A custom serializable class that replaces .NET&#8217;s MailAddress class (which is not serializable).</li>
<li><strong>SerialMailAttachment </strong>- A custom serializable class that replaces .NET&#8217;s MailAttachment class (which is not serializable).</li>
</ol>
<p>Please keep in mind that my SerialMailMessage code was intended for a web service, so there were certain limitations built into the design of the classes.  If you aren&#8217;t using these classes with a web service, you&#8217;ll have quite a bit more flexibility than I did.  I highly encourage you to modify and improve on my code &#8212; there is a shameful lack of useful custom serializable classes available online, hence the reason for me having to write my own.</p>
<p>If you have any questions, please post them as comments so that everyone can benefit from a discussion.</p>
]]></content:encoded>
			<wfw:commentRss>http://dotnetyuppie.com/2008/04/02/serializable-mailmessage-class/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Maximizing Your Firefox Screen Real Estate</title>
		<link>http://dotnetyuppie.com/2008/03/27/maximizing-your-firefox-screen-real-estate/</link>
		<comments>http://dotnetyuppie.com/2008/03/27/maximizing-your-firefox-screen-real-estate/#comments</comments>
		<pubDate>Thu, 27 Mar 2008 15:54:33 +0000</pubDate>
		<dc:creator>DotNetYuppie</dc:creator>
		
		<category><![CDATA[Firefox]]></category>

		<guid isPermaLink="false">http://dotnetyuppie.com/2008/03/27/maximizing-your-firefox-screen-real-estate/</guid>
		<description><![CDATA[If you&#8217;re developing on a laptop with a smaller screen, you can use all the screen real estate that you can get.  I have recently optimized my Firefox in order to maximize the amount of screen space available for web pages.


Hide the main menubar
As you can see above, I have hidden the &#8220;File, Edit, [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;re developing on a laptop with a smaller screen, you can use all the screen real estate that you can get.  I have recently optimized my Firefox in order to maximize the amount of screen space available for web pages.</p>
<p><img src='http://dotnetyuppie.com/wp-content/uploads/2008/03/optimizedscreenshot.jpg' alt='Optimized screen' /></p>
<p><span id="more-30"></span></p>
<p><strong>Hide the main menubar</strong><br />
As you can see above, I have hidden the &#8220;File, Edit, View, &#8230;&#8221; menu at the top, particularly because I rarely use my mouse to access the menu.  I almost always use hotkeys (like CTRL-B to access my bookmarks) to access the menu.  There is a Firefox extension, called <a href="https://addons.mozilla.org/en-US/firefox/addon/4762">Hide Menubar</a>, that allows you to hide the menu unless it is in use.  As you can see in the image below, you can enable or disable the main menu by right-clicking in the menu bar.  <a href="https://addons.mozilla.org/en-US/firefox/addon/4762">Click here to download the Hide Menubar extension.</a></p>
<p><img src='http://dotnetyuppie.com/wp-content/uploads/2008/03/hide-menubar.jpg' alt='Hide Menubar' /></p>
<p><strong>Use small icons for your theme</strong><br />
By right-clicking the main menu and clicking &#8216;Customize&#8230;&#8217;, you can reduce the size of your theme icons so that they are the same height as your URL textbox.  Select the &#8216;Use Small Icons&#8217; checkbox as shown below.</p>
<p><img src='http://dotnetyuppie.com/wp-content/uploads/2008/03/rightclickmenu.jpg' alt='Customize…' /></p>
<p><img src='http://dotnetyuppie.com/wp-content/uploads/2008/03/smallicons.jpg' alt='Small Icons' /></p>
<p><strong>Total Space Saved</strong><br />
On my machine, by both hiding the menu bar and using small icons, I save about 30 pixels of screen space (about 4% of my total screen resolution).  A 4% reduction in wasted space doesn&#8217;t seem like much, but it makes a significant visual difference while not diminishing the usability of Firefox.</p>
]]></content:encoded>
			<wfw:commentRss>http://dotnetyuppie.com/2008/03/27/maximizing-your-firefox-screen-real-estate/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Custom Binary Serialization in .NET</title>
		<link>http://dotnetyuppie.com/2008/02/17/custom-binary-serialization-in-net/</link>
		<comments>http://dotnetyuppie.com/2008/02/17/custom-binary-serialization-in-net/#comments</comments>
		<pubDate>Mon, 18 Feb 2008 04:11:26 +0000</pubDate>
		<dc:creator>DotNetYuppie</dc:creator>
		
		<category><![CDATA[Serialization]]></category>

		<category><![CDATA[Snippets]]></category>

		<guid isPermaLink="false">http://dotnetyuppie.com/2008/02/17/custom-binary-serialization-in-net/</guid>
		<description><![CDATA[In .NET, serialization is the process of converting a complex object into a bit stream or XML string, which can be saved into a file or sent over a network connection.  Serialization is extensively used in web services to transfer information from client to server, and for saving .NET objects into an SQL database.
In [...]]]></description>
			<content:encoded><![CDATA[<p>In .NET, serialization is the process of converting a complex object into a bit stream or XML string, which can be saved into a file or sent over a network connection.  Serialization is extensively used in web services to transfer information from client to server, and for saving .NET objects into an SQL database.</p>
<p>In this tutorial, I will show you how to implement binary serialization in .NET; you&#8217;ll quickly find that many objects in .NET are not natively serializable, so I&#8217;ll also show you how to customize an object to manually make it serializable.</p>
<p><span id="more-26"></span></p>
<p><strong>Serializable Objects</strong><br />
If an object is natively serializable, it is an extremely simple process to turn a complex object into a byte array.  The following class can be used in just about any situation to serialize or deserialize an object:</p>
<pre name="code" class="vb">

Imports System.Runtime.Serialization.Formatters.Binary
Imports System.IO

Public Class Serialization

Public Shared Function Serialize(ByVal Obj As Object) As Byte()
	Dim MS As New MemoryStream
	Dim BF As New BinaryFormatter
	BF.Serialize(MS, Obj)
	Return MS.ToArray
End Function

Public Shared Function Deserialize(ByVal SerializedData() As Byte) As Object
	Dim MS As New MemoryStream(SerializedData)
	Dim BF As New BinaryFormatter
	Return BF.Deserialize(MS)
End Function

End Class
</pre>
<p>The following example, utilizing the &#8216;Serialization&#8217; class from above, will convert &#8216;SomeObject&#8217; into a byte array and back into a generic object.  Note that the &#8216;Object&#8217; can be casted into whatever you want:</p>
<pre name="code" class="vb">

Dim SerializedData() as Byte = Serialization.Serialize(SomeObject)
Dim DeserializedObject as Object = Serialization.Deserialize(SerializedData)
</pre>
<p>Once an object is converted into a byte array, you can save it into an SQL database, write it to the disk, or even Response.BinaryWrite() it out to the user.</p>
<p><strong>Serialization of Unserializable Objects</strong><br />
There are quite a few objects in .NET (my most recent bout was with MailMessage and MailAddress) that cannot be serialized using the above method.  If you need to serialize these objects, you must tell .NET <em>how</em> an object should be serialized.    This often means that you&#8217;ll need to make a custom class that inherits an unserializable class, and then specify the class&#8217;s serialization map.</p>
<p>To manually specify how an object is serialized/deserialized, you need to include two functions.  I learn much better with examples rather than explanation, so I&#8217;ll give you the example first:</p>
<pre name="code" class="vb">

Imports System.Runtime.Serialization

&lt;Serializable()&gt; _
Public Class SomeClass
Implements ISerializable

Public SomeProperty As String

Public Sub New(ByVal info as SerializationInfo, ByVal c as StreamingContext)
	Me.SomeProperty = info.GetValue(&quot;SomeProperty&quot;, GetType(String))
End Sub

Public Sub GetObjectData(ByVal info SerializationInfo, ByVal context as StreamingContext) _
	Implements ISerializable.GetObjectData

	info.AddValue(&quot;SomeProperty&quot;, Me.SomeProperty, GetType(String))
End Sub
</pre>
<p><strong>Explanation</strong><br />
By including a New() and GetObjectData() method, .NET will know exactly how to serialize an object.  Without these methods, .NET would have no way of knowing how to convert your class into a bit stream, and it would throw an error.  I would like to point out a few small things of note in the above example:</p>
<ul>
<li>Include <strong>&lt;Serializable()&gt; _</strong> before you declare your class &#8212; this tells .NET that your class is serializable.  You need to include a <strong>(space)(underscore)</strong> because, unlike in C#, VB.NET pays attention to white space and it won&#8217;t associate your XML tag with the class.  If you&#8217;re weirded out with the underscore, you can just put everything on the same line, like <strong>&lt;Serializable()&gt; Public Class SomeClass</strong>.</li>
<li>Your class has to implement <strong>ISerializable</strong> &#8212; this allows you to use the GetObjectData() method later on.</li>
<li>The New() method is actually handling deserialization &#8212; it&#8217;s setting the <strong>Me.SomeProperty</strong> property based on the info object that is passed as an argument.</li>
<li>The GetObjectData() method must implement <strong>ISerializable.GetObjectData</strong>.  This method is responsible for serialization &#8212; it will store the <strong>Me.SomeProperty</strong> variable, which is a <strong>GetType(String)</strong>.</li>
</ul>
<p><strong>Custom Serialization</strong><br />
Once you&#8217;ve declared the GetType() and New() methods for your custom class, you can use the &#8216;Serialization&#8217; custom class at the beginning of this document to serialize your class just as if it was normally a serializable object.</p>
]]></content:encoded>
			<wfw:commentRss>http://dotnetyuppie.com/2008/02/17/custom-binary-serialization-in-net/feed/</wfw:commentRss>
		</item>
		<item>
		<title>How to Write BAT Files to Customize Your Development Environment</title>
		<link>http://dotnetyuppie.com/2008/02/04/how-to-write-bat-files-to-customize-your-development-environment/</link>
		<comments>http://dotnetyuppie.com/2008/02/04/how-to-write-bat-files-to-customize-your-development-environment/#comments</comments>
		<pubDate>Mon, 04 Feb 2008 13:38:19 +0000</pubDate>
		<dc:creator>DotNetYuppie</dc:creator>
		
		<category><![CDATA[Performance]]></category>

		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://dotnetyuppie.com/2008/02/04/how-to-write-bat-files-to-customize-your-development-environment/</guid>
		<description><![CDATA[I use the same machine to do development and to do all of my web surfing/school work/e-mails.  Often times I don&#8217;t want MSSQL server and IIS running when I&#8217;m not working because it wastes resources and slows down my computer.
Customize your environment
Windows makes it simple to customize your environment so services like IIS, MSSQL, [...]]]></description>
			<content:encoded><![CDATA[<p>I use the same machine to do development and to do all of my web surfing/school work/e-mails.  Often times I don&#8217;t want MSSQL server and IIS running when I&#8217;m not working because it wastes resources and slows down my computer.</p>
<p><strong>Customize your environment</strong><br />
Windows makes it simple to customize your environment so services like IIS, MSSQL, WebClient, etc. can be started and stopped just by running a small BAT file.  To create your own development environment BAT file:<span id="more-25"></span></p>
<ol>
<li>Open Notepad</li>
<li>Copy and paste the following text into notepad:
<pre name="code" class="sql">

	@echo off

	:start
	set /p _input=&quot;Server? [y/n]&quot;

	if %_input% equ y (
		echo Starting server services&#8230;
		sc start HTTPFilter 	REM HTTP SSL
		sc start IISADMIN		REM IIS Admin
		sc start lanmanserver	REM Server
		sc start MSSQLSERVER	REM SQL Server
		sc start SQLBrowser		REM SQL Server Browser
		sc start SQLWriter		REM SQL Server VSS Writer
		sc start W3SVC			REM World Wide Web Publishing
		sc start WebClient		REM WebClient

		set /p =&quot;Hit any key to continue&#8230;&quot;
	) else (
		echo STOPPING server services&#8230;
		sc stop HTTPFilter
		sc stop IISADMIN
		sc stop lanmanserver
		sc stop MSSQLSERVER
		sc stop SQLBrowser
		sc stop SQLWriter
		sc stop W3SVC
		sc stop WebClient

		set /p =&quot;Hit any key to continue&#8230;&quot;
	)

	:end
</pre>
</li>
<li>Save the file as <strong>Server.bat</strong> onto your desktop &#8212; you can name it whatever you like, as long as you have the file extension &#8216;.bat&#8217;</li>
<li>Double click the BAT file on your desktop &#8212; a command window will open, and prompt you with &#8220;Server? [y/n]&#8220;.  If you want to enable your development environment, hit &#8216;y&#8217; &#8212; if you want to disable your development environment, hit &#8216;n&#8217;</li>
</ol>
<p>This script is utilizing &#8220;sc stop&#8221; and &#8220;sc start&#8221;, which are both commands to start and stop different services.  Depending on your machine, your services may be different than mine.  I encourage you to customize the BAT file to start/stop whichever services you find pertinent to your development environment.  Unfortunately, some services (like MDM) don&#8217;t respond to &#8217;sc stop&#8217; &#8212; but this script is able to toggle some of the more important, resource-loving services.</p>
<p>You&#8217;ll find that by using this script, you can toggle between a development environment and a &#8216;fun&#8217; environment within seconds.  If you&#8217;re on a desktop machine that you also play games on, a script like this is invaluable to speed up your machine when you&#8217;re gaming, but still allow you to easily switch back to a development mode.</p>
]]></content:encoded>
			<wfw:commentRss>http://dotnetyuppie.com/2008/02/04/how-to-write-bat-files-to-customize-your-development-environment/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Self-Referencing Controls Within a GridView in Javascript</title>
		<link>http://dotnetyuppie.com/2008/01/11/self-referencing-controls-within-a-gridview-in-javascript/</link>
		<comments>http://dotnetyuppie.com/2008/01/11/self-referencing-controls-within-a-gridview-in-javascript/#comments</comments>
		<pubDate>Fri, 11 Jan 2008 21:57:01 +0000</pubDate>
		<dc:creator>DotNetYuppie</dc:creator>
		
		<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://dotnetyuppie.com/2008/01/11/self-referencing-controls-within-a-gridview-in-javascript/</guid>
		<description><![CDATA[Controls that are embedded in an ItemTemplate of a GridView can be tricky to reference in Javascript.  For example, if you want to pass the ClientID of a textbox to a function, the following example will not work:


&#60;script language=&#34;Javascript&#34; type=&#34;text/javascript&#34;&#62;
function AlertValue(SomeObject) {
    alert(SomeObject.value);
}
&#60;/script&#62;
[...]
&#60;asp:GridView ID=&#34;GridView1&#34; runat=&#34;server&#34;&#62;
    &#60;Columns&#62;
   [...]]]></description>
			<content:encoded><![CDATA[<p>Controls that are embedded in an ItemTemplate of a GridView can be tricky to reference in Javascript.  For example, if you want to pass the ClientID of a textbox to a function, the following example will <strong>not</strong> work:</p>
<pre name="code" class="html">

&lt;script language=&quot;Javascript&quot; type=&quot;text/javascript&quot;&gt;
function AlertValue(SomeObject) {
    alert(SomeObject.value);
}
&lt;/script&gt;
[...]
&lt;asp:GridView ID=&quot;GridView1&quot; runat=&quot;server&quot;&gt;
    &lt;Columns&gt;
        &lt;asp:TemplateField&gt;
            &lt;ItemTemplate&gt;
                &lt;asp:TextBox ID=&quot;SomeTextbox&quot; runat=&quot;server&quot;
                    onclick=&#8217;AlertValue(document.getElementById(&quot;&lt;%# SomeTextbox.ClientID %&gt;&quot;);&#8217;&gt;
                &lt;/asp:TextBox&gt;
            &lt;/ItemTemplate&gt;
        &lt;/asp:TemplateField&gt;
    &lt;/Columns&gt;
&lt;/asp:GridView&gt;
</pre>
<p><strong>Why doesn&#8217;t it work?</strong><br />
You can&#8217;t use ASP.NET&#8217;s ClientID property to return the object because the server id &#8216;SomeTextbox&#8217; is present in every row in the GridView &#8212; it&#8217;s not unique.  You can reference &#8216;SomeTextbox&#8217; in the code behind using the .FindControl method, but it&#8217;s much more involved than the work around below.</p>
<p><span id="more-23"></span></p>
<p><strong>The optimal work around</strong><br />
By using Javascript&#8217;s &#8216;this&#8217; keyword, we can reference the &#8216;SomeTextbox&#8217; control within the ItemTemplate code.  The &#8216;this&#8217; keyword refers to the owner of the object that is using &#8216;this&#8217; &#8212; for more information, check out <a href="http://www.quirksmode.org/js/this.html">Quirksmode - The this keyword</a>.  The following example is very similar to the above, incorrect example, except it uses Javascript to pass the ClientID to the &#8216;AlertValue&#8217; function.</p>
<pre name="code" class="html">

&lt;script language=&quot;Javascript&quot; type=&quot;text/javascript&quot;&gt;
function AlertValue(SomeObject) {
    alert(SomeObject.value);
}
&lt;/script&gt;
[...]
&lt;asp:GridView ID=&quot;GridView1&quot; runat=&quot;server&quot;&gt;
    &lt;Columns&gt;
        &lt;asp:TemplateField&gt;
            &lt;ItemTemplate&gt;
                &lt;asp:TextBox ID=&quot;SomeTextbox&quot; runat=&quot;server&quot;
                    onclick=&quot;AlertValue(this);&quot;&gt;&lt;/asp:TextBox&gt;
            &lt;/ItemTemplate&gt;
        &lt;/asp:TemplateField&gt;
    &lt;/Columns&gt;
&lt;/asp:GridView&gt;
</pre>
<p>Using the &#8216;this&#8217; keyword is a very basic in Javascript, but it can sometimes be easy to forget even the most basic things when you&#8217;re knee deep in ASP.NET and trying to solve a problem that is so simple it becomes complex.</p>
]]></content:encoded>
			<wfw:commentRss>http://dotnetyuppie.com/2008/01/11/self-referencing-controls-within-a-gridview-in-javascript/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Programmatically Recycling Your ASP.NET Application</title>
		<link>http://dotnetyuppie.com/2008/01/06/programmatically-recycling-your-aspnet-application/</link>
		<comments>http://dotnetyuppie.com/2008/01/06/programmatically-recycling-your-aspnet-application/#comments</comments>
		<pubDate>Sun, 06 Jan 2008 19:58:19 +0000</pubDate>
		<dc:creator>DotNetYuppie</dc:creator>
		
		<category><![CDATA[Snippets]]></category>

		<guid isPermaLink="false">http://dotnetyuppie.com/2008/01/06/programmatically-recycling-your-aspnet-application/</guid>
		<description><![CDATA[Occasionally an ASP.NET application needs to be recycled, particularly during testing, usually due to poor coding.  An application can be recycled in IIS, but if you don&#8217;t have access to IIS, you can programmatically recycle your ASP.NET application.
What is a recycle?
An application recycle releases all the resources and memory associated with an application, and [...]]]></description>
			<content:encoded><![CDATA[<p>Occasionally an ASP.NET application needs to be recycled, particularly during testing, usually due to poor coding.  An application can be recycled in IIS, but if you don&#8217;t have access to IIS, you can <strong>programmatically</strong> recycle your ASP.NET application.</p>
<p><strong>What is a recycle?</strong><br />
An application recycle releases all the resources and memory associated with an application, and restarts the application with a clean slate.  This process prevents memory-hog applications from taking up all a server&#8217;s resources with memory leaks and poor resource allocation.</p>
<p><span id="more-24"></span></p>
<p><strong>Why recycle?</strong><br />
An application, when coded correctly, should never need to be manually recycled; however, we don&#8217;t live in a perfect world, and sometimes poorly coded applications need to be manually recycled until a developer can fix the problem.  In my experience, the two most common reasons for needing a recycle is if the SQL connection pool is filled (due to a connection leak) or if I accidentally wrote an infinite loop.</p>
<p><strong>Method #1</strong><br />
The best and most straightforward method for application recycling is by using <strong>HttpRuntime.UnloadAppDomain()</strong>, which terminates the application and leaves it dead &#8212; the application will start up again once it received a request.  This method is especially useful for applications that are rarely used &#8212; an application can be terminated (so that it won&#8217;t take up memory) until it&#8217;s needed in the future.  The only downside to this method is that it requires high security permissions (PermissionState.Unrestricted) &#8212; if you don&#8217;t have full control of your environment, then you&#8217;ll need to consider method #2.</p>
<p><strong>Method #2</strong><br />
This method is more indirect, but will induce an application recycle.  By &#8216;touching&#8217; the Web.config file, IIS forces a recycle.  Any changes to the Web.config file, even to the &#8216;date last written&#8217;, will cause the recycle process.  This method is a bit more hack-ish, but it&#8217;s the best alternative to method #1.</p>
<p>Below is a function that recycles an application.  It will return true if a recycle was successful, and false if an error occurred while attempting a recycle.</p>
<pre name="code" class="vb">

Public Function RecycleApplication() As Boolean
    Dim Success As Boolean = True

    'Method #1
    '   It requires high security permissions, so it may not
    '   work in your environment
    Try
        HttpRuntime.UnloadAppDomain()
    Catch ex As Exception
        Success = False
    End Try

    If Not Success Then
        'Method #2
        '   By 'touching' the Web.config file, the application
        '   is forced to recycle
        Try
            Dim WebConfigPath As String = HttpContext.Current.Request.PhysicalApplicationPath + &quot;\\Web.config&quot;
            IO.File.SetLastWriteTimeUtc(WebConfigPath, DateTime.UtcNow)
        Catch ex As Exception
            Success = False
        End Try
    End If

    Return Success

End Function
</pre>
<p><strong>One last point</strong><br />
Please remember that manually recycling an application isn&#8217;t something that you should ever routinely have to do &#8212; it&#8217;s a quick-fix that can keep applications afloat until you can actually fix whatever problem is occurring.</p>
]]></content:encoded>
			<wfw:commentRss>http://dotnetyuppie.com/2008/01/06/programmatically-recycling-your-aspnet-application/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
