<?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"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>code.commongroove.com &#187; ASP.Net</title>
	<atom:link href="http://code.commongroove.com/category/asp-net/feed/" rel="self" type="application/rss+xml" />
	<link>http://code.commongroove.com</link>
	<description>C#, T-SQL, and general IT mojo</description>
	<lastBuildDate>Thu, 26 Jan 2012 03:00:48 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>ASP.Net: App_Offline.htm as a Maintenance Page</title>
		<link>http://code.commongroove.com/2011/09/16/asp-net-app_offline-htm-as-a-maintenance-page/</link>
		<comments>http://code.commongroove.com/2011/09/16/asp-net-app_offline-htm-as-a-maintenance-page/#comments</comments>
		<pubDate>Fri, 16 Sep 2011 15:40:35 +0000</pubDate>
		<dc:creator>Greg</dc:creator>
				<category><![CDATA[ASP.Net]]></category>
		<category><![CDATA[IIS]]></category>
		<category><![CDATA[MVC]]></category>

		<guid isPermaLink="false">http://code.commongroove.com/?p=311</guid>
		<description><![CDATA[While Googling about, I came upon an oldy-but-goody, that apparently has been available since the release of ASP.Net 2.0: App_Offline.htm. An undocumented feature, you can copy a file called app_offline.htm into the root of your .Net website and the application &#8230; <a href="http://code.commongroove.com/2011/09/16/asp-net-app_offline-htm-as-a-maintenance-page/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>While Googling about, I came upon an oldy-but-goody, that apparently has been available since the release of ASP.Net 2.0: App_Offline.htm.</p>
<p>An undocumented feature, you can copy a file called app_offline.htm into the root of your .Net website and the application will &#8220;bleed off&#8221; existing connections and redirect all new requests to the app_offline.htm page.</p>
<p>Once you remove the file, requests will again go back to your site.</p>
<p>Here&#8217;s ScottGu&#8217;s posts about it from back in 2005:</p>
<ul>
<li><a href="http://weblogs.asp.net/scottgu/archive/2005/10/06/426755.aspx" target="_blank">App_Offline.htm</a></li>
<li><a href="http://weblogs.asp.net/scottgu/archive/2006/04/09/442332.aspx" target="_blank">App_Offline.htm and working around the &#8220;IE Friendly Errors&#8221; feature</a></li>
</ul>
<p>One thing to note if you are using ASP.Net MVC.  Be sure your system.webserver configuration is set up to handle all requests so you don&#8217;t get 404s instead of the app_offline.htm page:</p>
<div class="codecolorer-container xml default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:550px;"><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;system.webServer<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;modules</span> <span style="color: #000066;">runAllManagedModulesForAllRequests</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/system.webServer<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></div></div>
]]></content:encoded>
			<wfw:commentRss>http://code.commongroove.com/2011/09/16/asp-net-app_offline-htm-as-a-maintenance-page/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ASP.Net MVC: Partially Secured Sites / Switching from HTTPS back to HTTP</title>
		<link>http://code.commongroove.com/2011/09/06/asp-net-mvc-partially-secured-sites-switching-from-https-back-to-http/</link>
		<comments>http://code.commongroove.com/2011/09/06/asp-net-mvc-partially-secured-sites-switching-from-https-back-to-http/#comments</comments>
		<pubDate>Tue, 06 Sep 2011 16:47:20 +0000</pubDate>
		<dc:creator>Greg</dc:creator>
				<category><![CDATA[ASP.Net]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[MVC]]></category>

		<guid isPermaLink="false">http://code.commongroove.com/?p=300</guid>
		<description><![CDATA[Most sites out there have some portions that should be only served via HTTPS, while the remainder can be HTTP, such as account pages and content pages respectively.  This is sometimes called a &#8220;partially secured site.&#8221; Starting with MVC 2, &#8230; <a href="http://code.commongroove.com/2011/09/06/asp-net-mvc-partially-secured-sites-switching-from-https-back-to-http/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Most sites out there have some portions that should be only served via HTTPS, while the remainder can be HTTP, such as account pages and content pages respectively.  This is sometimes called a &#8220;partially secured site.&#8221;</p>
<p>Starting with MVC 2, you could decorate controllers and actions with the <strong>RequireHttps</strong> attribute, which would redirect non-secure GET requests to HTTPS.  Unfortunately, once you are in HTTPS, you won&#8217;t automatically switch back to HTTP for those actions that do not require it.</p>
<p>To do that, you can override <strong>OnActionExecuting</strong> in your base controller (to save you from having to reimplement the call in each of your actual controllers) and redirect the user.</p>
<p>Here&#8217;s the code</p>
<div class="codecolorer-container csharp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:550px;"><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #008000;">&#91;</span>RequireHttps<span style="color: #008000;">&#93;</span><br />
<span style="color: #0600FF; font-weight: bold;">public</span> ActionResult MySslAction<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><br />
<span style="color: #008000;">&#123;</span><br />
<span style="color: #008080; font-style: italic;">// HTTPS</span><br />
<span style="color: #008000;">&#125;</span><br />
<br />
<span style="color: #0600FF; font-weight: bold;">public</span> ActionResult MyNonSslAction<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><br />
<span style="color: #008000;">&#123;</span><br />
<span style="color: #008080; font-style: italic;">// HTTP</span><br />
<span style="color: #008000;">&#125;</span><br />
<br />
<span style="color: #0600FF; font-weight: bold;">protected</span> <span style="color: #0600FF; font-weight: bold;">override</span> <span style="color: #6666cc; font-weight: bold;">void</span> OnActionExecuting<span style="color: #008000;">&#40;</span>ActionExecutingContext filterContext<span style="color: #008000;">&#41;</span><br />
<span style="color: #008000;">&#123;</span><br />
<span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>filterContext<span style="color: #008000;">.</span><span style="color: #0000FF;">HttpContext</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Request</span><span style="color: #008000;">.</span><span style="color: #0000FF;">IsSecureConnection</span> <span style="color: #008000;">&amp;&amp;</span> <span style="color: #008000;">!</span>filterContext<span style="color: #008000;">.</span><span style="color: #0000FF;">ActionDescriptor</span><span style="color: #008000;">.</span><span style="color: #0000FF;">IsDefined</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">typeof</span><span style="color: #008000;">&#40;</span>RequireHttpsAttribute<span style="color: #008000;">&#41;</span>, <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><br />
<span style="color: #008000;">&#123;</span><br />
<span style="color: #008080; font-style: italic;">// redirect to un-secured page</span><br />
<span style="color: #6666cc; font-weight: bold;">string</span> url <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;http://&quot;</span> <span style="color: #008000;">+</span> filterContext<span style="color: #008000;">.</span><span style="color: #0000FF;">HttpContext</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Request</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Url</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Host</span> <span style="color: #008000;">+</span> filterContext<span style="color: #008000;">.</span><span style="color: #0000FF;">HttpContext</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Request</span><span style="color: #008000;">.</span><span style="color: #0000FF;">RawUrl</span><span style="color: #008000;">;</span><br />
filterContext<span style="color: #008000;">.</span><span style="color: #0000FF;">HttpContext</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Response</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Redirect</span><span style="color: #008000;">&#40;</span>url<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<span style="color: #008000;">&#125;</span><br />
<br />
<span style="color: #0600FF; font-weight: bold;">base</span><span style="color: #008000;">.</span><span style="color: #0000FF;">OnActionExecuting</span><span style="color: #008000;">&#40;</span>filterContext<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<span style="color: #008000;">&#125;</span></div></div>
]]></content:encoded>
			<wfw:commentRss>http://code.commongroove.com/2011/09/06/asp-net-mvc-partially-secured-sites-switching-from-https-back-to-http/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>C#: String Extension to Replace Accented Characters</title>
		<link>http://code.commongroove.com/2011/04/29/c-string-extension-to-replace-accented-characters/</link>
		<comments>http://code.commongroove.com/2011/04/29/c-string-extension-to-replace-accented-characters/#comments</comments>
		<pubDate>Fri, 29 Apr 2011 13:47:39 +0000</pubDate>
		<dc:creator>Greg</dc:creator>
				<category><![CDATA[ASP.Net]]></category>
		<category><![CDATA[C#]]></category>

		<guid isPermaLink="false">http://code.commongroove.com/?p=284</guid>
		<description><![CDATA[Have you ever wanted to replace &#8220;accented&#8221; characters in a string with their equivalent English character?  Here&#8217;s a string extension that replaces these diacritics within a string for C# 2.0 and up: public static string ReplaceDiacritics&#40;this string source&#41; &#123; string &#8230; <a href="http://code.commongroove.com/2011/04/29/c-string-extension-to-replace-accented-characters/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Have you ever wanted to replace &#8220;accented&#8221; characters in a string with their equivalent English character?  Here&#8217;s a string extension that replaces these diacritics within a string for C# 2.0 and up:</p>
<div class="codecolorer-container csharp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:550px;"><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">string</span> ReplaceDiacritics<span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span> <span style="color: #6666cc; font-weight: bold;">string</span> source<span style="color: #008000;">&#41;</span><br />
<span style="color: #008000;">&#123;</span><br />
<span style="color: #6666cc; font-weight: bold;">string</span> sourceInFormD <span style="color: #008000;">=</span> source<span style="color: #008000;">.</span><span style="color: #0000FF;">Normalize</span><span style="color: #008000;">&#40;</span>NormalizationForm<span style="color: #008000;">.</span><span style="color: #0000FF;">FormD</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
var output <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> StringBuilder<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<span style="color: #0600FF; font-weight: bold;">foreach</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">char</span> c <span style="color: #0600FF; font-weight: bold;">in</span> sourceInFormD<span style="color: #008000;">&#41;</span><br />
<span style="color: #008000;">&#123;</span><br />
UnicodeCategory uc <span style="color: #008000;">=</span> CharUnicodeInfo<span style="color: #008000;">.</span><span style="color: #0000FF;">GetUnicodeCategory</span><span style="color: #008000;">&#40;</span>c<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>uc <span style="color: #008000;">!=</span> UnicodeCategory<span style="color: #008000;">.</span><span style="color: #0000FF;">NonSpacingMark</span><span style="color: #008000;">&#41;</span><br />
output<span style="color: #008000;">.</span><span style="color: #0000FF;">Append</span><span style="color: #008000;">&#40;</span>c<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<span style="color: #008000;">&#125;</span><br />
<br />
<span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #008000;">&#40;</span>output<span style="color: #008000;">.</span><span style="color: #0000FF;">ToString</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Normalize</span><span style="color: #008000;">&#40;</span>NormalizationForm<span style="color: #008000;">.</span><span style="color: #0000FF;">FormC</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<span style="color: #008000;">&#125;</span></div></div>
<p>The extension replaces characters like &#8220;&#246;&#8221; with &#8220;o&#8221;, &#8220;&#232&#8243; with &#8220;e&#8221; and &#8220;&#241;&#8221; with &#8220;n&#8221;.  This is great for getting acceptable URLs or for auto-complete / type-ahead search boxes where you want to match on both the accented and non-accented characters.</p>
]]></content:encoded>
			<wfw:commentRss>http://code.commongroove.com/2011/04/29/c-string-extension-to-replace-accented-characters/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JavaScript, UTF-8 Encoding: escape() vs. encodeURIComponent()</title>
		<link>http://code.commongroove.com/2009/08/06/javascript-utf-8-encoding-escape-vs-encodeuricomponent/</link>
		<comments>http://code.commongroove.com/2009/08/06/javascript-utf-8-encoding-escape-vs-encodeuricomponent/#comments</comments>
		<pubDate>Thu, 06 Aug 2009 23:07:00 +0000</pubDate>
		<dc:creator>Greg</dc:creator>
				<category><![CDATA[ASP.Net]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://code.commongroove.com/archive/2009/08/06/javascript-utf-8-encoding-escape-vs.-encodeuricomponent.aspx</guid>
		<description><![CDATA[ASP.Net web applications default to UTF-8 encoding.  Now, if you are using JavaScript to create or change URLs, you might run into an issue with the way the function &#8220;escape()&#8221; encodes characters if you are handling the decoding in your &#8230; <a href="http://code.commongroove.com/2009/08/06/javascript-utf-8-encoding-escape-vs-encodeuricomponent/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>ASP.Net web applications default to UTF-8 encoding.  Now, if you are using JavaScript to create or change URLs, you might run into an issue with the way the function &#8220;escape()&#8221; encodes characters if you are handling the decoding in your code behind via Request.QueryString.</p>
<p>To avoid ending up with &#8220;unkown&#8221; characters in your resultant string, use the JavaScript function &#8220;encodeURIComponent()&#8221; instead.  This should correctly encode your URLs for UTF-8.</p>
<p> </p>
<p> </p>
]]></content:encoded>
			<wfw:commentRss>http://code.commongroove.com/2009/08/06/javascript-utf-8-encoding-escape-vs-encodeuricomponent/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sys.WebForms.PageRequestManagerServerErrorException in FireFox with MSFT Ajax</title>
		<link>http://code.commongroove.com/2008/12/11/sys-webforms-pagerequestmanagerservererrorexception-in-firefox-with-msft-ajax/</link>
		<comments>http://code.commongroove.com/2008/12/11/sys-webforms-pagerequestmanagerservererrorexception-in-firefox-with-msft-ajax/#comments</comments>
		<pubDate>Thu, 11 Dec 2008 02:18:10 +0000</pubDate>
		<dc:creator>Greg</dc:creator>
				<category><![CDATA[ASP.Net]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[FireFox]]></category>
		<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://code.commongroove.com/archive/2008/12/10/sys.webforms.pagerequestmanagerservererrorexception-in-firefox-with-msft-ajax.aspx</guid>
		<description><![CDATA[If you encounter this error while navigating away from an AJAX-enabled page with a non-IE browser, you can silence it with the following JavaScript: if &#40;!document.all&#41; //non-ie &#123; window.onbeforeunload = function&#40;&#41; &#123; Sys.WebForms.PageRequestManager.getInstance&#40;&#41;.add_endRequest&#40;ignoreOnEndRequest&#41;; &#125; &#125; function ignoreOnEndRequest&#40;sender, e&#41; &#123; err &#8230; <a href="http://code.commongroove.com/2008/12/11/sys-webforms-pagerequestmanagerservererrorexception-in-firefox-with-msft-ajax/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>If you encounter this error while navigating away from an AJAX-enabled page with a non-IE browser, you can silence it with the following JavaScript:</p>
<div class="codecolorer-container javascript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:550px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>document.<span style="color: #660066;">all</span><span style="color: #009900;">&#41;</span> <span style="color: #006600; font-style: italic;">//non-ie</span><br />
<span style="color: #009900;">&#123;</span><br />
window.<span style="color: #660066;">onbeforeunload</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
Sys.<span style="color: #660066;">WebForms</span>.<span style="color: #660066;">PageRequestManager</span>.<span style="color: #660066;">getInstance</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">add_endRequest</span><span style="color: #009900;">&#40;</span>ignoreOnEndRequest<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #003366; font-weight: bold;">function</span> ignoreOnEndRequest<span style="color: #009900;">&#40;</span>sender<span style="color: #339933;">,</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
err <span style="color: #339933;">=</span> e.<span style="color: #660066;">get_error</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>err<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>err.<span style="color: #000066;">name</span> <span style="color: #339933;">==</span> <span style="color: #3366CC;">&quot;Sys.WebForms.PageRequestManagerServerErrorException&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
e.<span style="color: #660066;">set_errorHandled</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></div>
<p>Hope it works for you!<br />
﻿</p>
]]></content:encoded>
			<wfw:commentRss>http://code.commongroove.com/2008/12/11/sys-webforms-pagerequestmanagerservererrorexception-in-firefox-with-msft-ajax/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

