<?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/"
	
xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#"
>

<channel>
	<title>Nuno Gomes /* Code Adventures */</title>
	<atom:link href="http://blog.nunogomes.net/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.nunogomes.net</link>
	<description>var myInterests = new { language : &#34;C#&#34;, technology: &#34;ASP.NET&#34; };</description>
	<lastBuildDate>Sun, 26 Nov 2017 01:45:53 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=5.2.4</generator>

<image>
	<url>http://blog.nunogomes.net/wp-content/uploads/2016/11/cropped-linkedin_bg-32x32.jpg</url>
	<title>Nuno Gomes /* Code Adventures */</title>
	<link>http://blog.nunogomes.net</link>
	<width>32</width>
	<height>32</height>
</image> 
<site xmlns="com-wordpress:feed-additions:1">138817456</site>	<item>
		<title>Technical News &#8211; Typescript free eBook</title>
		<link>http://blog.nunogomes.net/post/2016/04/19/technical-news-typescript-free-ebook/</link>
				<pubDate>Tue, 19 Apr 2016 21:31:34 +0000</pubDate>
		<dc:creator><![CDATA[Nuno Gomes]]></dc:creator>
				<category><![CDATA[eBooks]]></category>
		<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://blog.nunogomes.net/2016/04/19/technical-news-typescript-free-ebook/</guid>
				<description><![CDATA[For those of you who think that structured and organized javascript is not an option but the “only” way to properly code for sure Typescrit won&#8217;t be a strange. If the dark side of the force is not for you then this book will strength your Jedy powers take you to the next level. Here’s... <p><a class="more-link" href="http://blog.nunogomes.net/post/2016/04/19/technical-news-typescript-free-ebook/">read more</a></p>]]></description>
								<content:encoded><![CDATA[<p>For those of you who think that structured and organized javascript is not an option but the “only” way to properly code for sure Typescrit won&#8217;t be a strange.</p>
<p>If the dark side of the force is not for you then this book will strength your Jedy powers take you to the next level.</p>
<p>Here’s some quotes about Typescript:</p>
<blockquote><p>“TypeScript is a superset of JavaScript which primarily provides optional static typing, classes and interfaces. One of the big benefits is to enable IDEs to provide a richer environment for spotting common errors as you type the code.”</p>
<p>“It’s open source, and we like that. It’s trustworthy also, because it is supported by a big organization (Microsoft) with an investment in making developers successful.”</p>
<p>“For a large JavaScript project, adopting TypeScript might result in more robust software, while still being deployable where a regular JavaScript application would run.”</p></blockquote>
<p>The eBook can be found <a href="http://bit.ly/1RNnPqK" target="_blank">here</a> and don’t forget to thank the author for making it available for free.</p>
<p>Enjoy it!</p>
]]></content:encoded>
									<post-id xmlns="com-wordpress:feed-additions:1">15</post-id>	</item>
		<item>
		<title>Viking Law #1</title>
		<link>http://blog.nunogomes.net/post/2012/07/25/viking-law-1/</link>
				<pubDate>Wed, 25 Jul 2012 01:24:00 +0000</pubDate>
		<dc:creator><![CDATA[Nuno Gomes]]></dc:creator>
				<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://blog.nunogomes.net/2012/07/25/viking-law-1/</guid>
				<description><![CDATA[Today, while reading this old post from Emil Gustafsson about the Viking Laws and how they can be projected into the software development context, I just can’t stop thinking that his first law interpretation is missing one of the most important, if not not the most important, commandment. Law #1 is all about bravery and... <p><a class="more-link" href="http://blog.nunogomes.net/post/2012/07/25/viking-law-1/">read more</a></p>]]></description>
								<content:encoded><![CDATA[<p>Today, while reading this old <a href="http://blogs.msdn.com/b/cellfish/archive/2010/06/07/viking-laws.aspx" target="_blank">post</a> from <a href="http://blog.cellfish.se/p/about.html" target="_blank">Emil Gustafsson</a> about the Viking Laws and how they can be projected into the software development context, I just can’t stop thinking that his first law interpretation is missing one of the most important, if not not the most important, commandment.</p>
<p>Law #1 is all about bravery and aggressiveness, and according to Emil it can be projected into software development as:</p>
<ul>
<li><em>Be direct</em></li>
<li><em>Grab all opportunities</em></li>
<li><em>Use varying methods of attack</em></li>
<li><em>Be versatile and agile</em></li>
<li><em>Attack one target at a time</em></li>
<li><em>Don’t plan everything in detail</em></li>
<li><em>Use top quality weapons</em></li>
</ul>
<p>I totally agree with all these commandments but one is missing and I think it should be the first:</p>
<ul>
<li><em>Choose your targets wisely</em></li>
</ul>
<blockquote><p>Never attack a target when you know you’re not enough skilled to win. Sometimes the greatest bravery you can show is to recognize you’re not ready.</p></blockquote>
]]></content:encoded>
									<post-id xmlns="com-wordpress:feed-additions:1">16</post-id>	</item>
		<item>
		<title>Enum types, FlagsAttribute &#038; Zero value – Part 2</title>
		<link>http://blog.nunogomes.net/post/2012/07/06/enum-types-flagsattribute-zero-value-part-2/</link>
				<pubDate>Fri, 06 Jul 2012 02:26:00 +0000</pubDate>
		<dc:creator><![CDATA[Nuno Gomes]]></dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[ASP.NET]]></category>

		<guid isPermaLink="false">http://blog.nunogomes.net/2012/07/06/enum-types-flagsattribute-zero-value-part-2/</guid>
				<description><![CDATA[In my previous post I wrote about why you should pay attention when using enum value Zero. After reading that post you are probably thinking like Benjamin Roux: Why don&#8217;t you start the enum values at 0x1? Well I could, but doing that I lose the ability to have Sync and Async mutually exclusive by... <p><a class="more-link" href="http://blog.nunogomes.net/post/2012/07/06/enum-types-flagsattribute-zero-value-part-2/">read more</a></p>]]></description>
								<content:encoded><![CDATA[<p>In my previous post I wrote about why you should pay attention when using enum value Zero.<br />
After reading that post you are probably thinking like <a href="https://weblogs.asp.net/broux" target="_blank">Benjamin Roux</a>: Why don&#8217;t you start the <code>enum</code> values at <code>0x1</code>?<br />
Well I could, but doing that I lose the ability to have Sync and Async mutually exclusive by design. Take a look at the following enum types:</p>
<pre>[Flags]
public enum OperationMode1
{
    Async = 0x1,
    Sync = 0x2,
    Parent = 0x4
}

[Flags]
public enum OperationMode2
{
    Async = 0x0,
    Sync = 0x1,
    Parent = 0x2
}</pre>
<p><span id="more-17"></span></p>
<p>To achieve mutually exclusion between Sync and Async values using <code><span style="color: #2b91af;">OperationMode1 </span></code>you would have to operate both values:</p>
<pre class="code">protected void CheckMainOperarionMode(OperationMode1 mode)
{
    switch (mode)
    {
        case (OperationMode1.Async | OperationMode1.Sync | OperationMode1.Parent):
        case (OperationMode1.Async | OperationMode1.Sync):
            throw new InvalidOperationException("Cannot be Sync and Async simultaneous");
            break;
        case (OperationMode1.Async | OperationMode1.Parent):
        case (OperationMode1.Async):
            break;
        case (OperationMode1.Sync | OperationMode1.Parent):
        case (OperationMode1.Sync):
            break;
        default:
            throw new InvalidOperationException("No default mode specified");
    }
}</pre>
<p>but this is a <em>by design</em> constraint in <code>OperationMode2</code>. Why? Simply because <code>0x0</code> is the neutral element for the bitwise OR operation.<br />
Knowing this singularity, replacing and simplifying the previous method, you get:</p>
<pre class="code"><code>protected void CheckMainOperarionMode(OperationMode2 mode)
{
    switch (mode)
    {
        case (OperationMode2.Sync | OperationMode2.Parent):
        case (OperationMode2.Sync):
            break;
        case (OperationMode2.Parent):
        default:
            break;
    }
}</code></pre>
<p>This means that:</p>
<ul>
<li>if both Sync and Async values are specified Sync value always win (Zero is the neutral element for bitwise OR operation)</li>
<li>if no Sync value specified, the Async method is used.</li>
</ul>
<p>Here is the final method implementation:</p>
<pre class="code"><code>protected void CheckMainOperarionMode(OperationMode2 mode)
{
    if (mode &amp; OperationMode2.Sync == OperationMode2.Sync)
    {
    } else { 
    }
}</code></pre>
<p>All content above prove that Async value (<code>0x0</code>) is useless from the arithmetic perspective, but, without it we lose readability.<br />
The following IF statements are logically equals but the first is definitely more readable:</p>
<pre class="code"><code>if (OperationMode2.Async | OperationMode2.Parent)
{
}

if (OperationMode2.Parent)
{ 
}</code></pre>
<p>Here&#8217;s another example where you can see the benefits of 0x0 value, the default value can be used explicitly.</p>
<pre class="code"><code>&lt;my:Control runat="server" Mode="Async,Parent"&gt;

&lt;my:Control runat="server" Mode="Parent"&gt;</code></pre>
<p>&nbsp;</p>
]]></content:encoded>
									<post-id xmlns="com-wordpress:feed-additions:1">17</post-id>	</item>
		<item>
		<title>Enum types, FlagsAttribute &#038; Zero value</title>
		<link>http://blog.nunogomes.net/post/2012/07/05/enum-types-flagsattribute-zero-value/</link>
				<pubDate>Thu, 05 Jul 2012 02:15:16 +0000</pubDate>
		<dc:creator><![CDATA[Nuno Gomes]]></dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[ASP.NET]]></category>

		<guid isPermaLink="false">http://blog.nunogomes.net/2012/07/05/enum-types-flagsattribute-zero-value/</guid>
				<description><![CDATA[We all know about Enums types and use them every single day. What is not that often used is to decorate the Enum type with the FlagsAttribute. When an Enum type has the FlagsAttribute we can assign multiple values to it and thus combine multiple information into a single enum. The enum values should be... <p><a class="more-link" href="http://blog.nunogomes.net/post/2012/07/05/enum-types-flagsattribute-zero-value/">read more</a></p>]]></description>
								<content:encoded><![CDATA[<p>We all know about Enums types and use them every single day. What is not that often used is to decorate the Enum type with the <a href="http://msdn.microsoft.com/en-us/library/system.flagsattribute.aspx" target="_blank">FlagsAttribute</a>.</p>
<p>When an Enum type has the <a href="http://msdn.microsoft.com/en-us/library/system.flagsattribute.aspx" target="_blank">FlagsAttribute</a> we can assign multiple values to it and thus combine multiple information into a single enum.</p>
<p>The enum values should be a power of two so that a bit set is achieved.</p>
<p>Here is a typical Enum type:</p>
<pre class="code"><code>public enum OperationMode
{
    /// &lt;summary&gt;
    /// No operation mode
    /// &lt;/summary&gt;
    None = 0,
    /// &lt;summary&gt;
    /// Standard operation mode
    /// &lt;/summary&gt;
    Standard = 1,
    /// &lt;summary&gt;
    /// Accept bubble requests mode
    /// &lt;/summary&gt;
    Parent = 2
}</code></pre>
<p><span id="more-18"></span></p>
<p>In such scenario no values combination are possible. In the following scenario a default operation mode exists and combination is used:</p>
<pre class="code"><code>[Flags]
public enum OperationMode
{
    /// &lt;summary&gt;
    /// Asynchronous operation mode
    /// &lt;/summary&gt;
    Async = 0,
    /// &lt;summary&gt;
    /// Synchronous operation mode
    /// &lt;/summary&gt;
    Sync = 1,
    /// &lt;summary&gt;
    /// Accept bubble requests mode
    /// &lt;/summary&gt;
    Parent = 2
}</code></pre>
<p>Now, it’s possible to do statements like:</p>
<pre><code>[DefaultValue(OperationMode.Async)]</code>
<code>[TypeConverter(typeof(EnumConverter))]
public OperationMode Mode { get; set; }

/// &lt;summary&gt;
/// Gets a value indicating whether this instance supports request from childrens.
/// &lt;/summary&gt;
public bool IsParent
{
    get { return (this.Mode &amp; OperationMode.Parent) == OperationMode.Parent; }
}</code></pre>
<p>or</p>
<pre><code>switch (this.Mode)
{
    case OperationMode.Sync | OperationMode.Parent:
        Console.WriteLine("Sync,Parent");
        break;</code>

<code>[…]</code></pre>
<p>But there is something that you should never forget: <a href="http://en.wikipedia.org/wiki/Absorbing_element" target="_blank">Zero is the absorber element for the bitwise AND operation</a>.</p>
<p>So, checking for <code>OperationMode.Async</code> (the Zero value) mode just like the OperationMode.Parent mode makes no sense since it will always be true:</p>
<pre class="code"><code>(this.Mode &amp; 0x0) == 0x<span style="color: #2b91af;">0</span></code></pre>
<p>Instead, inverse logic should be used: OperationMode.Async = !OperationMode.Sync</p>
<pre class="code"><code>public bool IsAsync
{
    get { return (this.Mode &amp; ContentManagerOperationMode.Sync) != ContentManagerOperationMode.Sync; }
}</code></pre>
<p>or</p>
<pre class="code"><code>public bool IsAsync
{
    get { return (int)this.Mode == 0; }
}</code></pre>
<blockquote><p>Some readers suggested to use the <a href="http://msdn.microsoft.com/en-us/library/system.enum.hasflag.aspx" target="_blank">Enum.HasFlag</a> method. Although it’s another valid approach it’s also widely accepted that this method has some performance issues related an internal box/unboxing. Use it when performance is not a problem (I see this method mostly used by rookie developers).</p></blockquote>
<h1>Final Note:</h1>
<h3>Benefits</h3>
<blockquote>
<h5>Allow multiple values combination</h5>
</blockquote>
<p>The above samples snippets were taken from an ASP.NET control and enabled the following markup usage:</p>
<pre class="code"><code>&lt;my:Control runat="server" Mode="Sync,Parent"&gt;
</code></pre>
<h3>Drawback</h3>
<blockquote>
<h5>Zero value is the absorber element for the bitwise AND operation</h5>
</blockquote>
<p>Be very carefully when evaluating the Zero value, either evaluate the enum value as an integer or use inverse logic.</p>
]]></content:encoded>
									<post-id xmlns="com-wordpress:feed-additions:1">18</post-id>	</item>
		<item>
		<title>OpenXML error “file is corrupt and cannot be opened.”</title>
		<link>http://blog.nunogomes.net/post/2012/06/20/openxml-error-file-is-corrupt-and-cannot-be-opened/</link>
				<pubDate>Wed, 20 Jun 2012 00:39:33 +0000</pubDate>
		<dc:creator><![CDATA[Nuno Gomes]]></dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[ASP.NET]]></category>

		<guid isPermaLink="false">http://blog.nunogomes.net/2012/06/20/openxml-error-file-is-corrupt-and-cannot-be-opened/</guid>
				<description><![CDATA[From time to time I ear some people saying their new web application supports data export to Excel format. So far so good … but they don’t tell the all story … in fact almost all the times what is happening is they are exporting data to a Comma-Separated file or simply exporting GridView rendered... <p><a class="more-link" href="http://blog.nunogomes.net/post/2012/06/20/openxml-error-file-is-corrupt-and-cannot-be-opened/">read more</a></p>]]></description>
								<content:encoded><![CDATA[<p>From time to time I ear some people saying their new web application supports data export to Excel format.</p>
<p>So far so good … but they don’t tell the all story … in fact almost all the times what is happening is they are exporting data to a <a href="http://en.wikipedia.org/wiki/Comma-separated_values" target="_blank">Comma-Separated file</a> or simply <a href="http://www.codedigest.com/articles/aspnet/130_export_to_excel_in_aspnet_20_%E2%80%93gridview_to_excel_datatable_to_excel.aspx" target="_blank">exporting GridView rendered HTML</a> to an xls file.</p>
<p>Ok … it works but it’s not something I would be proud of.</p>
<p>So … yesterday I decided to take a look at the <a href="http://www.ecma-international.org/publications/standards/Ecma-376.htm" target="_blank">Office Open XML File Formats Specification</a> (Microsoft Office 2007+ format) based on well-known technologies: <a href="http://en.wikipedia.org/wiki/Zip_(file_format)" target="_blank">ZIP</a> and <a href="http://en.wikipedia.org/wiki/XML" target="_blank">XML</a>.<span id="more-19"></span></p>
<p>I start by installing <a href="http://www.microsoft.com/en-us/download/details.aspx?id=5124" target="_blank">Open XML SDK 2.0 for Microsoft Office</a> and playing with some samples.</p>
<p>Then I decided to try it on a more complex web application and the <span style="color: #a5a5a5;"><em>“file is corrupt and cannot be opened.”</em></span> message start happening.</p>
<p><a href="http://www.google.com/search?q=openxml+%22the+file+is+corrupt+and+cannot+be+opened%22" target="_blank">Google show us</a> that many people suffer from the same and it seems there are many reasons that can trigger this message. Some are related to the process itself, others with encodings or even styling.</p>
<p>Well, none solved my problem and I had to dig … well not that much, I simply change the output file extension to zip and extract the zip content.</p>
<p>Then I did the same to the output file from my first sample, compare both zip contents with <a href="http://sourcegear.com/diffmerge/index.html" target="_blank">SourceGear DiffMerge</a> and found that my problem was Culture related.</p>
<p>Yes, my complex application sets the <a href="http://msdn.microsoft.com/en-us/library/system.threading.thread.currentculture.aspx" target="_blank">Thread.CurrentThread.CurrentCulture</a>  to a non-English culture.</p>
<p>For sample purposes I was simply using the <a href="http://msdn.microsoft.com/library/system.object.tostring(v=vs.100).aspx" target="_blank">ToString</a> method to convert numbers and dates to a string representation but forgot that XML is culture invariant and thus using a decimal separator other than “.” will result in a deserialization problem.</p>
<p>I solve the <em><span style="color: #a5a5a5;">“file is corrupt and cannot be opened.”</span></em> by using <a href="http://msdn.microsoft.com/en-us/library/ms131008.aspx" target="_blank">Convert.ToString(object, CultureInfo.InvariantCulture)</a> method instead of the <a href="http://msdn.microsoft.com/library/system.object.tostring(v=vs.100).aspx" target="_blank">ToString</a> method.</p>
<p>Hope this can help someone.</p>
]]></content:encoded>
									<post-id xmlns="com-wordpress:feed-additions:1">19</post-id>	</item>
		<item>
		<title>ELWEA &#8211; EventLog WebEvent Aggregator for ASP.NET</title>
		<link>http://blog.nunogomes.net/post/2011/04/27/elwea-eventlog-webevent-aggregator-for-asp-net/</link>
				<pubDate>Wed, 27 Apr 2011 01:48:31 +0000</pubDate>
		<dc:creator><![CDATA[Nuno Gomes]]></dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[CodeProject]]></category>

		<guid isPermaLink="false">http://blog.nunogomes.net/2011/04/28/elwea-eventlog-webevent-aggregator-for-asp-net/</guid>
				<description><![CDATA[Last time I wrote about Health Monitoring was during 2008 and since then I ‘m using, on a daily basis, a complex Health Monitoring EventLog provider to aggregate WebEvents from specific ASP.NET web applications. Last year I found ELMAH (Error Logging Module and Handler) project and became a fan of the concept: “[…] facility that... <p><a class="more-link" href="http://blog.nunogomes.net/post/2011/04/27/elwea-eventlog-webevent-aggregator-for-asp-net/">read more</a></p>]]></description>
								<content:encoded><![CDATA[<p>Last time I wrote about <a href="/post/2008/08/25/asp-net-health-monitoring-building-an-eventlogwebeventprovider-part-3/" target="_blank">Health Monitoring was during 2008</a> and since then I ‘m using, on a daily basis, a complex Health Monitoring EventLog provider to aggregate WebEvents from specific ASP.NET web applications.</p>
<p>Last year I found <a href="http://code.google.com/p/elmah/" target="_blank">ELMAH (Error Logging Module and Handler) project</a> and became a fan of the concept:</p>
<blockquote><p><em>“[…] facility that is completely pluggable. It can be dynamically added to a running </em><a href="http://www.asp.net/"><em>ASP.NET</em></a><em> web application, or even all ASP.NET web applications on a machine, without any need for re-compilation or re-deployment.”</em></p></blockquote>
<p>It didn’t take much time until I start thinking  about releasing a version of my EventLog WebEvents aggregator.<span id="more-20"></span></p>
<p>I’m now happy to announce that I finally made this project available at <a href="http://codeplex.com/" target="_blank">Codeplex</a> and name it: <a href="http://elwea.codeplex.com/" target="_blank">ELWEA &#8211; EventLog WebEvent Aggregator for ASP.NET</a>.</p>
<p>While different in nature this project main goal is pretty similar to the ELMAH project: keep an ASP.NET web application error tracking isolated and easily accessible.</p>
<p>What makes this project different from many other like ELMAH is the fact that it&#8217;s not focused on handling and persisting error info. This project main goal is to aggregate all EventLog data belong to a specific web application under a specific EventLog source name.</p>
<table border="0" cellspacing="0" cellpadding="2">
<tbody>
<tr>
<td valign="top">Before</td>
<td valign="top">After</td>
</tr>
<tr>
<td valign="top"><img class="aligncenter" src="http://www.codeplex.com/Project/Download/FileDownload.aspx?ProjectName=elwea&amp;DownloadId=227438" width="475" height="137" /></td>
<td valign="top"><img class="aligncenter" src="http://www.codeplex.com/Project/Download/FileDownload.aspx?ProjectName=elwea&amp;DownloadId=230377" width="509" height="137" /></td>
</tr>
</tbody>
</table>
<p>I’m sure that web developer and web site administrators will love it but I think that also IT pros that manage shared hosting environments will use it.</p>
<p>Visit <a href="http://elwea.codeplex.com/" target="_blank">here</a> for a more complete description and <a href="http://elwea.codeplex.com/documentation" target="_blank">here</a> for the project documentation.</p>
<p>To make your live even simpler I’m planning to make a <a href="http://nuget.codeplex.com/" target="_blank">NuGet</a> package available for ELWEA. Keep an eye on this.</p>
<p>Enjoy it!</p>
]]></content:encoded>
									<post-id xmlns="com-wordpress:feed-additions:1">20</post-id>	</item>
		<item>
		<title>.NET – ArrayList hidden gem</title>
		<link>http://blog.nunogomes.net/post/2011/02/04/net-arraylist-hidden-gem/</link>
				<pubDate>Fri, 04 Feb 2011 00:50:56 +0000</pubDate>
		<dc:creator><![CDATA[Nuno Gomes]]></dc:creator>
				<category><![CDATA[.NET]]></category>

		<guid isPermaLink="false">http://blog.nunogomes.net/2011/02/04/net-arraylist-hidden-gem/</guid>
				<description><![CDATA[From time to time I end-up finding really old hidden gems and a few days ago I found another one. IList System.Collections.ArrayList.ReadOnly(IList list) This amazing method is available since the beginning (.NET 1.0). I always complain about the small support for ReadOnly lists and collections and I have no clue why I miss this one.... <p><a class="more-link" href="http://blog.nunogomes.net/post/2011/02/04/net-arraylist-hidden-gem/">read more</a></p>]]></description>
								<content:encoded><![CDATA[<p>From time to time I end-up finding really old hidden gems and a few days ago I found another one.</p>
<pre class="code"><code><a href="http://msdn.microsoft.com/en-us/library/system.collections.arraylist.readonly(v=vs.71).aspx" target="_blank">IList System.Collections.ArrayList.ReadOnly(IList list)</a></code></pre>
<p>This amazing method is available since the beginning (.NET 1.0).</p>
<p>I always complain about the small support for ReadOnly lists and collections and I have no clue why I miss this one.</p>
<p>For those of you that have to maintain and extend legacy applications prior to ASP.NET 2.0 SP2 this could be a very useful finding.</p>
]]></content:encoded>
									<post-id xmlns="com-wordpress:feed-additions:1">21</post-id>	</item>
		<item>
		<title>ASP.NET Controls &#8211; System.Web.UI.HtmlControls.HtmlButton client click hits the server twice</title>
		<link>http://blog.nunogomes.net/post/2010/10/14/asp-net-controls-system-web-ui-htmlcontrols-htmlbutton-client-click-hits-the-server-twice/</link>
				<pubDate>Thu, 14 Oct 2010 07:43:17 +0000</pubDate>
		<dc:creator><![CDATA[Nuno Gomes]]></dc:creator>
				<category><![CDATA[ASP.NET]]></category>

		<guid isPermaLink="false">http://blog.nunogomes.net/2010/10/15/asp-net-controls-system-web-ui-htmlcontrols-htmlbutton-client-click-hits-the-server-twice/</guid>
				<description><![CDATA[At work we have about 5000 PC&#8217;s that are mainly our commercial network. All those PC use intranet services and web applications. Until a few months ago IE6 was our corporate browser (yep) but we ended moving to IE8. A few days ago someone came to me saying that their application appears to have some... <p><a class="more-link" href="http://blog.nunogomes.net/post/2010/10/14/asp-net-controls-system-web-ui-htmlcontrols-htmlbutton-client-click-hits-the-server-twice/">read more</a></p>]]></description>
								<content:encoded><![CDATA[<p>At work we have about 5000 PC&#8217;s that are mainly our commercial network. All those PC use intranet services and web applications.</p>
<p>Until a few months ago IE6 was our corporate browser (yep) but we ended moving to IE8.</p>
<p>A few days ago someone came to me saying that their application appears to have some problem because every time they click some HTML buttons the server gets two hits.</p>
<p>Also they are able to say that this didn&#8217;t happen when they used the IE6.</p>
<p>In the faulty application the buttons that trigger two posts were System.Web.UI.HtmlControls.HtmlButton controls with Click event handlers registered.</p>
<p>After some research I found that the default type attribute value for HTML BUTTON element has changed in IE8 and later (<a href="http://msdn.microsoft.com/en-us/library/ms534696(v=VS.85).aspx">here</a>).</p>
<ul>
<li>In IE7 and earlier the default value is &#8216;button&#8217;</li>
<li>In IE8 and later the default value is &#8216;submit&#8217;</li>
</ul>
<p><span id="more-22"></span>This changed in browser default behavior was not reflected in the Server-Control that renders it: it doesn&#8217;t set the type attribute value to button when a postback is required.</p>
<p>Without such change, every time we attached a Click event handler to a HtmlButton we endup with two posts: one triggered by the _doPostback function and another from the form itself (caused by the default type=&#8217;submit&#8217; value.).</p>
<p>I easily bypass this problem by setting the type attribute value to &#8216;button&#8217; in my base control.</p>
<p>Even so, I think that this change should be done by the framework itself when a postback is required in a HtmlButton.</p>
<p>After some &#8216;reflection&#8217; I propose changing the System.Web.UI.Util.WriteOnClickAttribute method to do the job.</p>
<p>Such change would ensure the some behavior independent of the browser version.</p>
<p>If you have another workaround or you think I&#8217;m completely wrong please let me know.</p>
<p>Also if you think this is a real problem that should be solved then visit this <a href="https://connect.microsoft.com/VisualStudio/feedback/details/612858/htmlbutton-client-click-hits-the-server-twice">Connect entry</a> I create.</p>
]]></content:encoded>
									<post-id xmlns="com-wordpress:feed-additions:1">22</post-id>	</item>
		<item>
		<title>ASP.NET Controls – Problem sorting GridView with SqlDataSource control</title>
		<link>http://blog.nunogomes.net/post/2010/10/09/asp-net-controls-problem-sorting-gridview-with-sqldatasource-control/</link>
				<pubDate>Sat, 09 Oct 2010 03:47:52 +0000</pubDate>
		<dc:creator><![CDATA[Nuno Gomes]]></dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Controls]]></category>

		<guid isPermaLink="false">http://blog.nunogomes.net/?p=90</guid>
				<description><![CDATA[Let me start by saying that Microsoft don&#39;t consider this issue as a problem, as you can see here this is a “by design&#8221; behavior. The problem is well described in the referred Connect feedback and it contains a workaround. Although simple, the workaround requires you to always register the GridView Sorting event and make... <p><a class="more-link" href="http://blog.nunogomes.net/post/2010/10/09/asp-net-controls-problem-sorting-gridview-with-sqldatasource-control/">read more</a></p>]]></description>
								<content:encoded><![CDATA[<p>
Let me start by saying that Microsoft don&#39;t consider this issue as a problem, as you can see <a href="https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=102618" target="_blank">here</a> this is a “by design&rdquo; behavior.
</p>
<p>
The problem is well described in the referred Connect feedback and it contains a workaround.
</p>
<p>
Although simple, the workaround requires you to always register the <a href="http://msdn.microsoft.com/library/system.web.ui.webcontrols.gridview.aspx" target="_blank">GridView</a> <a href="http://msdn.microsoft.com/library/system.web.ui.webcontrols.gridview.sorting.aspx" target="_blank">Sorting event</a> and make the tweak according to the current GridView settings. Well, if are like me you will forget to do it half the times needed.
</p>
<p>
So, I made a not so simple workaround that will take care of the issue for me.
</p>
<p>
I override the <a href="http://msdn.microsoft.com/library/system.web.ui.webcontrols.gridview.onsorting.aspx" target="_blank">OnSorting</a> method from GridView so I can handle the <a href="http://msdn.microsoft.com/library/system.web.ui.webcontrols.gridviewsorteventargs.aspx" target="_blank">GridViewEventArgs</a> instance and override its <a href="http://msdn.microsoft.com/library/system.web.ui.webcontrols.gridviewsorteventargs.sortdirection.aspx" target="_blank">SortDirection</a> value.
</p>
<p>
To turn this into a general solution I partially reproduce the ParseSortString method from <a href="http://msdn.microsoft.com/library/system.data.datatable.aspx" target="_blank">DataTable</a> to find out if the current <a href="http://msdn.microsoft.com/library/system.web.ui.webcontrols.gridview.sortexpression.aspx" target="_blank">SortExpression</a> contains either the ASC or DESC keywords.
</p>
<p>
Here is the code:
</p>
<pre class="code"><code>public class GridView : global::System.Web.UI.WebControls.GridView
{
    protected override void OnSorting(GridViewSortEventArgs e)
    {
        if (!string.IsNullOrEmpty(this.SortExpression))
        {
            if (this.SortExpression.Equals(this.SortExpression))
            {
                bool isMultipleSortExpression;
                SortDirection? sortDirection = GetSortDirection(this.SortExpression, out isMultipleSortExpression);
                if (sortDirection.HasValue)
                {
                    // To undo bug in GridView.HandleSort(string sortExpression) and then in GridView.CreateDataSourceSelectArguments()
                    e.SortDirection = SortDirection.Ascending;
                }
            }
        }
        base.OnSorting(e);
    }

    private SortDirection? GetSortDirection(string sortExpression, out bool isMultipleSortExpression)
    {
        SortDirection? sortDirection = null;
        isMultipleSortExpression = false;

        string[] strArray = sortExpression.Split(new char[] { ',' });
        for (int i = 0; i < strArray.Length; i++)
        {
            string strA = strArray[i].Trim();
            int length = strA.Length;
            if ((length >= 5) && (string.Compare(strA, length - 4, " ASC", 0, 4, StringComparison.OrdinalIgnoreCase) == 0))
            {
                sortDirection = SortDirection.Ascending;
            }
            else if ((length >= 6) && (string.Compare(strA, length - 5, " DESC", 0, 5, StringComparison.OrdinalIgnoreCase) == 0))
            {
                sortDirection = SortDirection.Descending;
            }
            if (!sortDirection.HasValue)
            {
                break;
            }
        }
        if (sortDirection.HasValue)
        {
            if (strArray.Length > 1)
            {
                isMultipleSortExpression = true;
            }
        }
        return sortDirection;
    }
}</code></pre>
<p>
Enjoy it.</p>
]]></content:encoded>
									<post-id xmlns="com-wordpress:feed-additions:1">90</post-id>	</item>
		<item>
		<title>Patch For ASP.NET Vulnerability Available</title>
		<link>http://blog.nunogomes.net/post/2010/09/28/patch-for-asp-net-vulnerability-available/</link>
				<pubDate>Tue, 28 Sep 2010 21:06:02 +0000</pubDate>
		<dc:creator><![CDATA[Nuno Gomes]]></dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Security]]></category>

		<guid isPermaLink="false">http://blog.nunogomes.net/2010/09/28/patch-for-asp-net-vulnerability-available/</guid>
				<description><![CDATA[Microsoft has published a Security Advisory (2416728) about a security vulnerability in ASP.NET on Saturday, September 18th. This vulnerability exists in all versions of ASP.NET and was publically disclosed late Friday at a security conference. Scott Guthrie has provided information on workarounds (please see Important: ASP.NET Security Vulnerability and ASP.NET Security Vulnerability) to prevent attackers... <p><a class="more-link" href="http://blog.nunogomes.net/post/2010/09/28/patch-for-asp-net-vulnerability-available/">read more</a></p>]]></description>
								<content:encoded><![CDATA[<p align="justify"><a title="Microsoft Corporation" href="http://www.microsoft.com/" target="_blank">Microsoft</a> has published a <a title="Microsoft Security Advisory (2416728) - Vulnerability in ASP.NET Could Allow Information Disclosure" href="http://www.microsoft.com/technet/security/advisory/2416728.mspx" target="_blank">Security Advisory (2416728)</a> about a security vulnerability in <a title="ASP.NET Developer Center" href="http://msdn.microsoft.com/asp.net/" target="_blank">ASP.NET</a> on Saturday, September 18th. This vulnerability exists in all versions of <strong>ASP.NET</strong> and was publically disclosed late Friday at a security conference.</p>
<p align="justify"><a title="ScottGu's Blog" href="http://weblogs.asp.net/scottgu/default.aspx" target="_blank">Scott Guthrie</a> has provided information on workarounds (please see <a title="Important: ASP.NET Security Vulnerability" href="http://weblogs.asp.net/scottgu/archive/2010/09/18/important-asp-net-security-vulnerability.aspx" target="_blank">Important: ASP.NET Security Vulnerability</a> and <a title="ASP.NET Security Vulnerability" href="http://weblogs.asp.net/scottgu/archive/2010/09/24/update-on-asp-net-vulnerability.aspx" target="_blank">ASP.NET Security Vulnerability</a>) to prevent attackers from using this vulnerability against their ASP.NET applications.</p>
<p align="justify">To help with Microsoft’s response to the new padding oracle vulnerability, a new forum was also set up: <a href="http://forums.asp.net/1233.aspx">Security Vulnerability</a>.</p>
<p align="justify">Microsoft has now <a title="Microsoft Security Bulletin MS10-070 - Important" href="http://www.microsoft.com/technet/security/bulletin/ms10-070.mspx" target="_blank">announced</a> the release of an out-of-band security update to address the ASP.NET Security Vulnerability.</p>
<p align="justify">Applying the update addresses the ASP.NET Security Vulnerability, and once the update is applied to your system <a title="Important: ASP.NET Security Vulnerability" href="http://weblogs.asp.net/scottgu/archive/2010/09/18/important-asp-net-security-vulnerability.aspx" target="_blank">the workarounds</a> Scott has previously blogged about will no longer be required. But, until the update has been installed, those workarounds must be used.</p>
<p align="justify">You can learn more about this security update release from this reading the <a title="Out of Band Release to Address Microsoft Security Advisory 2416728" href="http://blogs.technet.com/b/msrc/archive/2010/09/27/out-of-band-release-to-address-microsoft-security-advisory-2416728.aspx" target="_blank">Microsoft Security Response Center Blog Post</a> as well as the official <a title="Microsoft Security Bulletin MS10-070 - Important" href="http://www.microsoft.com/technet/security/bulletin/ms10-sep.mspx" target="_blank">Advance Notification Bulletin</a>.</p>
<p align="left">Important Links:</p>
<ul>
<li>
<div align="justify"><a title="Important: ASP.NET Security Vulnerability" href="http://weblogs.asp.net/scottgu/archive/2010/09/18/important-asp-net-security-vulnerability.aspx" target="_blank">Important: ASP.NET Security Vulnerability</a></div>
</li>
<li>
<div align="justify"><a title="ASP.NET Security Vulnerability" href="http://weblogs.asp.net/scottgu/archive/2010/09/24/update-on-asp-net-vulnerability.aspx" target="_blank">ASP.NET Security Vulnerability</a></div>
</li>
<li>
<div align="left"><a title="Out of Band Release to Address Microsoft Security Advisory 2416728" href="http://blogs.technet.com/b/msrc/archive/2010/09/27/out-of-band-release-to-address-microsoft-security-advisory-2416728.aspx" target="_blank">Out of Band Release to Address Microsoft Security Advisory 2416728</a></div>
</li>
<li>
<div align="left"><a title="Microsoft Security Bulletin MS10-070 - Important" href="http://www.microsoft.com/technet/security/bulletin/ms10-sep.mspx" target="_blank">Microsoft Security Bulletin MS10-070 – Important</a></div>
</li>
</ul>
]]></content:encoded>
									<post-id xmlns="com-wordpress:feed-additions:1">23</post-id>	</item>
	</channel>
</rss>
