﻿<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:blogChannel="http://backend.userland.com/blogChannelModule" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#">
  <channel>
    <title>Volkan Uzun</title>
    <description>Cruising in .NET seas</description>
    <link>http://www.msnetprogrammer.net/blog/</link>
    <docs>http://www.rssboard.org/rss-specification</docs>
    <generator>BlogEngine.NET 1.6.0.0</generator>
    <language>en-US</language>
    <blogChannel:blogRoll>http://www.msnetprogrammer.net/blog/opml.axd</blogChannel:blogRoll>
    <blogChannel:blink>http://www.dotnetblogengine.net/syndication.axd</blogChannel:blink>
    <dc:creator>Volkan Uzun</dc:creator>
    <dc:title>Volkan Uzun</dc:title>
    <geo:lat>3,405,556.000000</geo:lat>
    <geo:long>-1,171,817.000000</geo:long>
    <item>
      <title>Infinite loop between STS and SharePoint</title>
      <description>&lt;blockquote&gt;   &lt;p&gt;&amp;#160;&amp;#160;&amp;#160; If you setup SharePoint to use a STS for authentication, you may have an infinite loop problem like I did :) Here was my scenario:&lt;/p&gt;    &lt;p&gt;I have a custom STS, and I setup a trust relation between this STS and SharePoint. When I try to login to a site, as expected, the browser is forwarded to STS login page. I typed in my username and password, then browser started redirection to SharePoint and then again back to STS. This was an infinite loop, and it was weird that Internet Explorer does not complain when there is an infinite loop.&lt;/p&gt;    &lt;p&gt;Anyway, when I googled this situation, first link was: &lt;a href="http://blogs.technet.com/b/speschka/archive/2010/08/09/setting-the-login-token-expiration-correctly-for-sharepoint-2010-saml-claims-users.aspx" target="_blank"&gt;Setting the Login Token Expiration Correctly for SharePoint 2010 SAML Claims Users&lt;/a&gt;. I applied the suggestions which basically were changing the default timeouts. However this did not fix the problem. &lt;/p&gt;    &lt;p&gt;I started thinking about the scenarios that could cause this problem. I know from the logs that STS login worked perfectly ok, and it created claims, and sent it to SharePoint. SharePoint was probably refusing the claims, and sending the user back to STS, STS was redirecting to SharePoint again (as there was a session cookie after then authentication) … The problem was when I was setting up the claims, I had a typo, and SharePoint was expecting another claim from STS, and hence causing the infinite loop.&lt;/p&gt;    &lt;p&gt;I fixed the claim typo problem, and tried it again, nope again infinite loop. with the help of my one of my colleagues, we found the problem. When I click the site from IIS manager (click browse link next to the site), IIS is using localhost address, and this was causing the infinite loop. However when I type in the real address (not the localhost one), everything was working as expected :)&lt;/p&gt;&lt;/blockquote&gt;</description>
      <link>http://www.msnetprogrammer.net/blog/post/2011/01/03/Infinite-loop-between-STS-and-SharePoint.aspx</link>
      <author>volkanuzun</author>
      <comments>http://www.msnetprogrammer.net/blog/post/2011/01/03/Infinite-loop-between-STS-and-SharePoint.aspx#comment</comments>
      <guid>http://www.msnetprogrammer.net/blog/post.aspx?id=1f315154-b931-4327-ac13-19bbe79c741e</guid>
      <pubDate>Mon, 03 Jan 2011 16:47:08 -0600</pubDate>
      <category>SharePoint</category>
      <dc:publisher>volkanuzun</dc:publisher>
      <pingback:server>http://www.msnetprogrammer.net/blog/pingback.axd</pingback:server>
      <pingback:target>http://www.msnetprogrammer.net/blog/post.aspx?id=1f315154-b931-4327-ac13-19bbe79c741e</pingback:target>
      <slash:comments>0</slash:comments>
      <trackback:ping>http://www.msnetprogrammer.net/blog/trackback.axd?id=1f315154-b931-4327-ac13-19bbe79c741e</trackback:ping>
      <wfw:comment>http://www.msnetprogrammer.net/blog/post/2011/01/03/Infinite-loop-between-STS-and-SharePoint.aspx#comment</wfw:comment>
      <wfw:commentRss>http://www.msnetprogrammer.net/blog/syndication.axd?post=1f315154-b931-4327-ac13-19bbe79c741e</wfw:commentRss>
    </item>
    <item>
      <title>A potentially dangerous Request.Form value was detected from the client (wresult="&lt;trust:RequestSecuri...").</title>
      <description>&lt;blockquote&gt;   &lt;p&gt;I created my first sample WIF application after hearing so much about it. I used the ASP.NET MVC default project that comes with Visual Studio 2010 using .NET 4.0.&amp;#160; I did not do anything special just created the ASP.NET MVC project, right clicked on the project, clicked add the sts reference and ran the project. The browser was forwarded to the login page, I put some random password, and clicked login button. I got the error you see in the title: “A potentially dangerous Request.Form value was detected from the client (wresult=&amp;quot;&amp;lt;trust:RequestSecuri...&amp;quot;).”      &lt;br /&gt;The reason for this error is the claim coming back from the STS project is xml format, and that triggers and fails the ASP.NET validation. What you have to do is write a custom validation, and configure your application to use this custom validation. WIF SDK has a sample custom validation which under default installation is at: “C:\Program Files (x86)\Windows Identity Foundation SDK\v4.0\Samples\Quick Start\Web Application\WebControlBasedClaimsAwareWebApp\App_Code\SampleRequestValidator.cs”.&lt;/p&gt;    &lt;p&gt;There is a class in this file that derives from: RequestValidator and overrides IsValidRequestString. In this function it checks if the request is coming from our STS service or not. If it is not coming from our service, basically it calls the base validator. Here is the code that does this:      &lt;br /&gt;&lt;/p&gt;    &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; WIFRequestValidator:RequestValidator
    {
        &lt;span class="kwrd"&gt;protected&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; &lt;span class="kwrd"&gt;bool&lt;/span&gt; IsValidRequestString(HttpContext context, &lt;br /&gt;            &lt;span class="kwrd"&gt;string&lt;/span&gt; &lt;span class="kwrd"&gt;value&lt;/span&gt;, RequestValidationSource requestValidationSource, &lt;br /&gt;            &lt;span class="kwrd"&gt;string&lt;/span&gt; collectionKey,  &lt;span class="kwrd"&gt;out&lt;/span&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt; validationFailureIndex)
        {
            validationFailureIndex = 0;
            &lt;span class="kwrd"&gt;if&lt;/span&gt; (requestValidationSource == RequestValidationSource.Form &amp;amp;&amp;amp;
                collectionKey.Equals(WSFederationConstants.Parameters.Result, &lt;br /&gt;                StringComparison.Ordinal))
            {
                SignInResponseMessage message =WSFederationMessage.&lt;br /&gt;                 CreateFromFormPost(context.Request) &lt;span class="kwrd"&gt;as&lt;/span&gt; SignInResponseMessage;
                &lt;span class="kwrd"&gt;if&lt;/span&gt; (message != &lt;span class="kwrd"&gt;null&lt;/span&gt;)
                    &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;true&lt;/span&gt;;
            }
            &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;base&lt;/span&gt;.IsValidRequestString(context, &lt;span class="kwrd"&gt;value&lt;/span&gt;, &lt;br /&gt;                requestValidationSource, collectionKey, &lt;br /&gt;                &lt;span class="kwrd"&gt;out&lt;/span&gt; validationFailureIndex);
        }
    }&lt;/pre&gt;
  &lt;style type="text/css"&gt;


.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;&lt;/blockquote&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;To use this validator in your application instead of the default ASP.NET validator, you have to modify web.config file. Open up the web.config file, and add/modify this line as follows:&lt;/p&gt;

&lt;pre&gt;&amp;lt;httpRuntime requestValidationType=&amp;quot;WIF2.WIFRequestValidator&amp;quot; /&amp;gt;&lt;br /&gt;&lt;/pre&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;Now you run the code and you probably get your second error message:&lt;/p&gt;

&lt;p&gt;&lt;font color="#ff0000"&gt;&lt;strong&gt;ID1038: The AudienceRestrictionCondition was not valid because the specified Audience is not present in AudienceUris.&lt;/strong&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p&gt;I don’t know if this is a bug in the WIF system or not, but to solve this issue, you need to modify the web.config for the web application one more time. Go to the line where you see:
  &lt;br /&gt;“&amp;lt;wsFederation passiveRedirectEnabled..

  &lt;br /&gt;and go to section realm=”… and add a / to the end of the url. Such as in my config file before I did the update it was:

  &lt;br /&gt;realm=&lt;a href="http://localhost/wif2"&gt;http://localhost/wif2&lt;/a&gt;

  &lt;br /&gt;and I changed it to:

  &lt;br /&gt;realm=&lt;a href="http://localhost/wif2/"&gt;http://localhost/wif2/&lt;/a&gt;

  &lt;br /&gt;&lt;/p&gt;

&lt;p&gt;That is it :)&lt;/p&gt;</description>
      <link>http://www.msnetprogrammer.net/blog/post/2010/10/14/A-potentially-dangerous-RequestForm-value-was-detected-from-the-client-(wresult3d3ctrustRequestSecuri).aspx</link>
      <author>volkanuzun</author>
      <comments>http://www.msnetprogrammer.net/blog/post/2010/10/14/A-potentially-dangerous-RequestForm-value-was-detected-from-the-client-(wresult3d3ctrustRequestSecuri).aspx#comment</comments>
      <guid>http://www.msnetprogrammer.net/blog/post.aspx?id=42093f4a-1462-493c-8ba5-38638c196cdd</guid>
      <pubDate>Thu, 14 Oct 2010 15:58:05 -0600</pubDate>
      <dc:publisher>volkanuzun</dc:publisher>
      <pingback:server>http://www.msnetprogrammer.net/blog/pingback.axd</pingback:server>
      <pingback:target>http://www.msnetprogrammer.net/blog/post.aspx?id=42093f4a-1462-493c-8ba5-38638c196cdd</pingback:target>
      <slash:comments>0</slash:comments>
      <trackback:ping>http://www.msnetprogrammer.net/blog/trackback.axd?id=42093f4a-1462-493c-8ba5-38638c196cdd</trackback:ping>
      <wfw:comment>http://www.msnetprogrammer.net/blog/post/2010/10/14/A-potentially-dangerous-RequestForm-value-was-detected-from-the-client-(wresult3d3ctrustRequestSecuri).aspx#comment</wfw:comment>
      <wfw:commentRss>http://www.msnetprogrammer.net/blog/syndication.axd?post=42093f4a-1462-493c-8ba5-38638c196cdd</wfw:commentRss>
    </item>
    <item>
      <title>New Era</title>
      <description>&lt;p&gt;I am changing my programming interests in the last few months. I am more interested in security, windows identity foundation, federated authorization and Sharepoint.&amp;#160; I am not new into security,&amp;#160; I presented OWASP Security Vulnerability, many times I was the one helping to fix the SQL injections or other security vulnerabilities found at work.    &lt;br /&gt;However I am new to Windows Identity Foundation and Sharepoint. I installed Sharepoint a virtual machine and started playing with it. Unfortunately Sharepoint is not very intuitive and user friendly. Most of the actions are not at the places you look for. As far as I can experience in the last 1 month, it is not developer friendly either :). All the resources you find are for beginners, and advanced blogs do not share the source code. &lt;/p&gt;  &lt;p&gt;I will start sharing what I learn about Sharepoint and WIF in this blog from beginner to advanced level :)&lt;/p&gt;  &lt;p&gt;Let the games begin…&lt;/p&gt;</description>
      <link>http://www.msnetprogrammer.net/blog/post/2010/10/10/New-Era.aspx</link>
      <author>volkanuzun</author>
      <comments>http://www.msnetprogrammer.net/blog/post/2010/10/10/New-Era.aspx#comment</comments>
      <guid>http://www.msnetprogrammer.net/blog/post.aspx?id=3f4ca4eb-2f3a-4ff5-b5db-20683d47e8b3</guid>
      <pubDate>Sun, 10 Oct 2010 02:28:11 -0600</pubDate>
      <dc:publisher>volkanuzun</dc:publisher>
      <pingback:server>http://www.msnetprogrammer.net/blog/pingback.axd</pingback:server>
      <pingback:target>http://www.msnetprogrammer.net/blog/post.aspx?id=3f4ca4eb-2f3a-4ff5-b5db-20683d47e8b3</pingback:target>
      <slash:comments>0</slash:comments>
      <trackback:ping>http://www.msnetprogrammer.net/blog/trackback.axd?id=3f4ca4eb-2f3a-4ff5-b5db-20683d47e8b3</trackback:ping>
      <wfw:comment>http://www.msnetprogrammer.net/blog/post/2010/10/10/New-Era.aspx#comment</wfw:comment>
      <wfw:commentRss>http://www.msnetprogrammer.net/blog/syndication.axd?post=3f4ca4eb-2f3a-4ff5-b5db-20683d47e8b3</wfw:commentRss>
    </item>
    <item>
      <title>Socal CodeCamp Reviews</title>
      <description>&lt;p&gt;I attended the 2 day Socal CodeCamp in San Diego which is a great event that I think all the developers in the area should attend. I am a frequent CodeCamp attendee :) , and usually enjoy the sessions. &lt;/p&gt;  &lt;p&gt;I did not see a huge crowd this time at the CodeCamp (purely personal observation, you should talk to CodeCamp management for real data which says one of the most crowded codecamp in San Diego). It is summer time, people may have more fun stuff to do such as surfing :). Actually I even heard someone would go surfing in between&amp;#160; sessions :). &lt;/p&gt;  &lt;p&gt;If you look at the interest tag cloud for the sessions this time there are lot of Sql Server, Silverlight, 101 XXX, Step by Step XXX.&amp;#160; It seems that people are interested in Beginner Level sessions. Once again this is purely personal observation, and people may attend different sessions and choose other sessions :).&amp;#160; &lt;br /&gt;Overall the quality of the sessions that I attended were good, I mean when it is free, why would you complain right? But I still will :)).&lt;/p&gt;  &lt;p&gt;I think some hours of the codecamp should be purely dedicated to more advanced sessions. Such as on Saturday sessions at 9 – 12, all sessions are advanced, this will help to arrange schedule for visitors.&lt;/p&gt;  &lt;p&gt;Another issue, is lot’s of repeating.&amp;#160; Microsoft is coming out with lot’s different tools, and other communities such as Mono community is coming with lot’s different tools, and we don’t get a change to listen any talks about most of these.&amp;#160; I know the real question is then why don’t take the steps and learn one of these and give a talk :) Well, for this fall I am planning about it. &lt;/p&gt;</description>
      <link>http://www.msnetprogrammer.net/blog/post/2010/07/02/Socal-CodeCamp-Reviews.aspx</link>
      <author>volkanuzun</author>
      <comments>http://www.msnetprogrammer.net/blog/post/2010/07/02/Socal-CodeCamp-Reviews.aspx#comment</comments>
      <guid>http://www.msnetprogrammer.net/blog/post.aspx?id=2edf5fcc-10b1-4093-bbbc-9ed158e0bc21</guid>
      <pubDate>Fri, 02 Jul 2010 21:33:25 -0600</pubDate>
      <dc:publisher>volkanuzun</dc:publisher>
      <pingback:server>http://www.msnetprogrammer.net/blog/pingback.axd</pingback:server>
      <pingback:target>http://www.msnetprogrammer.net/blog/post.aspx?id=2edf5fcc-10b1-4093-bbbc-9ed158e0bc21</pingback:target>
      <slash:comments>0</slash:comments>
      <trackback:ping>http://www.msnetprogrammer.net/blog/trackback.axd?id=2edf5fcc-10b1-4093-bbbc-9ed158e0bc21</trackback:ping>
      <wfw:comment>http://www.msnetprogrammer.net/blog/post/2010/07/02/Socal-CodeCamp-Reviews.aspx#comment</wfw:comment>
      <wfw:commentRss>http://www.msnetprogrammer.net/blog/syndication.axd?post=2edf5fcc-10b1-4093-bbbc-9ed158e0bc21</wfw:commentRss>
    </item>
    <item>
      <title>HandleError attribute (MVC)</title>
      <description>&lt;p&gt;&amp;#160;&amp;#160;&amp;#160; In ASP.NET MVC you can decorate the action methods and the controllers with filter attributes to control their behavior.&amp;#160; These filters are injected into the pipeline, and depending on their type; they are executed before/after something happens. You can either use the filters that come with the framework, or write your own filters. Even though it is easy to test the functionality of the filters, it may not be easy to test if the controller/action is/are decorated with the filter (You can use reflection).&amp;#160; There are 4 different types of filters that come with the framework:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;strong&gt;Authorization Filter&lt;/strong&gt;: These type of filters have very high priority, and run before other types of filters or the action execution. &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;Action Filter&lt;/strong&gt;: These type of filters have normal priority, and run before and after the action execution, by this way you can do some work before&amp;#160; an action is executed or after an action is executed. A good example could be logging the system activity, or calculating the time that takes to execute the action. &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;Result Filter:&lt;/strong&gt; These type of filters have&amp;#160; normal priority, and run before and after the action result is executed, by this way, you can manipulate the action results. &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;Exception Filter&lt;/strong&gt;: These filters are executed if an unhandled exception is thrown. &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;In this blog posting I will be explaining HandleError attribute which is a type of Exception Filter. You may want to use this filter to catch the exception for either logging the exception to a log file or display a nice error page so the user does not freak out.&amp;#160; If you create a default MVC project using Visual Studio, you will see that the HomeController class is decorated with HandleError filter.&lt;/p&gt;  &lt;pre class="csharpcode"&gt;[HandleError]
&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; HomeController : Controller&lt;/pre&gt;
&lt;style type="text/css"&gt;



.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;
  &lt;br /&gt;This means whenever there is an exception that is not handled, render the Error view, so when there is an exception the framework will first look at the folder “Views/Home” and check if there is an Error.aspx page (assuming you are using the default WebForms Engine). If it can not find this page, it will check if there is a Error.ascx page, if there is none, then the same search will be applied to Shared folder. Finally if there is an Error.aspx/ascx page found it will be rendered, otherwise, in the production system, IIS will handle error, in the development system you may see the error below (depending on your web.config customErrors setting).&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.msnetprogrammer.net/blog/image.axd?picture=image_7.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.msnetprogrammer.net/blog/image.axd?picture=image_thumb_7.png" width="429" height="82" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Or if you use the HandleError filter, and configure your system right, this may be the screen:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.msnetprogrammer.net/blog/image.axd?picture=image_8.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.msnetprogrammer.net/blog/image.axd?picture=image_thumb_8.png" width="382" height="103" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Of course you want to the second user friendly error page. Let’s first see what we should be doing to get the simple user friendly user page and then we will look into customizing this error page.&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Decorate the controller or the action method with HandleError &lt;/li&gt;

  &lt;li&gt;Create an Error.aspx or Error.ascx page, and put this page either into the View folder of the controller or Shared folder. &lt;/li&gt;

  &lt;li&gt;Open your web.config file and change the custom errors definition to customErrors mode=”On” &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;
  &lt;br /&gt;After this 3 simple steps, you have&amp;#160; an Error page that will be displayed whenever there is an unhandled exception. 

  &lt;br /&gt;&lt;/p&gt;

&lt;p&gt;HandleErrorAttribute is defined in the HandlErrorAttributed.cs (suprised?) file. It is a relatively simple and short code. If you check the source code, you will see that there are parameters you can customize.&amp;#160; Here are the list of the parameters that you can customize:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;View: You can define a new View besides the Error to render for the error message. If you don’t specify a View name, default View name is Error &lt;/li&gt;

  &lt;li&gt;Master: You can define a master page for the View that will be rendered. If you don’t specify a master name, that it is empty by default, which means it will use the default master page. &lt;/li&gt;

  &lt;li&gt;ExceptionType: The exception type that you want to handle, by default it is the very generic System.Exception which means catch all the exceptions. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Note that there is another field you can customize however it is not a direct member of this class, but it comes with inheritance.&amp;#160; &lt;br /&gt;Going back to our example, if we want to change error page name to let’s say “UnderMaintenance” , simple change your filter decoration to:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;[HandleError(View=&lt;span class="str"&gt;&amp;quot;UnderMaintenance&amp;quot;&lt;/span&gt;)]
&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; HomeController : Controller&lt;/pre&gt;
&lt;style type="text/css"&gt;

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;
  &lt;br /&gt;Or if you want to change the master page to Maintenance simply change your filter decoration to:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;[HandleError(View=&lt;span class="str"&gt;&amp;quot;UnderMaintenance&amp;quot;&lt;/span&gt;, Master=&lt;span class="str"&gt;&amp;quot;Maintenance&amp;quot;&lt;/span&gt;)]
&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; HomeController : Controller&lt;/pre&gt;
&lt;style type="text/css"&gt;

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;
  &lt;br /&gt;Now let’s assume you want to redirect the user to different pages for different types of exceptions, then you have to use the ExceptionType property.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;If the View you are trying to render is not found, then InvalidOperationException will be thrown. &lt;/li&gt;

  &lt;li&gt;If you are trying to connect to SqlServer, and there is an error, then System.Data.SqlClient.SqlException will be thrown &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For other types of exception you can check MSDN, but let’s now concentrate on these 2 exceptions, and create 2 different error pages for 2 different types of Exceptions. Here is the right decoration for this goal:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;[HandleError(View=&lt;span class="str"&gt;&amp;quot;Error&amp;quot;&lt;/span&gt;, ExceptionType=&lt;span class="kwrd"&gt;typeof&lt;/span&gt;(InvalidOperationException))
[HandleError(View=&lt;span class="str"&gt;&amp;quot;DatabaseError&amp;quot;&lt;/span&gt;,ExceptionType=&lt;br /&gt;                &lt;span class="kwrd"&gt;typeof&lt;/span&gt;(System.Data.SqlClient.SqlException))
&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; HomeController: Controller&lt;/pre&gt;
&lt;style type="text/css"&gt;

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;
  &lt;br /&gt;By this declaration we are telling the system that when there is an InvalidOperationException render the Error.aspx/ascx, when there is a SqlException&amp;#160; error, render DatabaseError.aspx/ascx view.&lt;/p&gt;

&lt;p&gt;What happens when we add another HandleError that handles the SystemException which is basically all the exceptions, so if our declaration is like below, and assume SqlException is thrown:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;[HandleError(ExceptionType=&lt;span class="kwrd"&gt;typeof&lt;/span&gt;(InvalidOperationException))]
[HandleError(ExceptionType=&lt;span class="kwrd"&gt;typeof&lt;/span&gt;(System.Data.SqlClient.SqlException))]
[HandleError(ExceptionType = &lt;span class="kwrd"&gt;typeof&lt;/span&gt;(SystemException))]
 &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; HomeController : Controller&lt;/pre&gt;
&lt;style type="text/css"&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;
  &lt;br /&gt;The framework will call&amp;#160; the all filters that can catch this type of exception, in this case, framework will call handlerror twice, one for the SqlException, and one for the SystemException. &lt;/p&gt;

&lt;p&gt;You can write your own HandleError filter, and apply it to the controller or action. Inside this filter, you have to set the ExceptionHandled flag to true, so that framework won’t throw the yellow dead screen. If there are more than 1 filter that can catch the error message, all of them have to set the ExceptionHandled flag to true, or framework will throw the yellow dead screen. 
  &lt;br /&gt;The default HandleError attribute also creates a model for your view incase you want to get more information about the error, if you change your error page’s model to HandleErrorInfo, then you can get more information from the framework about the error. A simple example for the Error.aspx could be:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="asp"&gt;&amp;lt;%@ Page ..  Inherits=&amp;quot;System.Web.Mvc.ViewPage&amp;lt;HandleErrorInfo&amp;gt;&amp;quot; %&amp;gt;&lt;/span&gt;
Sorry for the error, We are working hard on it to fix the problem.
&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;ul&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;li&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;Action: &lt;span class="asp"&gt;&amp;lt;%&lt;/span&gt;=Model.ActionName &lt;span class="asp"&gt;%&amp;gt;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;li&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;li&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;Controller: &lt;span class="asp"&gt;&amp;lt;%&lt;/span&gt;=Model.ControllerName &lt;span class="asp"&gt;%&amp;gt;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;li&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;li&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;span class="asp"&gt;&amp;lt;%&lt;/span&gt;=Model.Exception.ToString() &lt;span class="asp"&gt;%&amp;gt;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;li&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;ul&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;style type="text/css"&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;Of course in the real work application, you don’t want to display this information to your user, but you can use this information to write a log to your log system.
  &lt;br /&gt;Hopefully this article help you to understand HandleError attribute. &lt;/p&gt;

&lt;p&gt;May the force be with you.&lt;/p&gt;</description>
      <link>http://www.msnetprogrammer.net/blog/post/2010/03/27/HandleError-attribute-(MVC).aspx</link>
      <author>volkanuzun</author>
      <comments>http://www.msnetprogrammer.net/blog/post/2010/03/27/HandleError-attribute-(MVC).aspx#comment</comments>
      <guid>http://www.msnetprogrammer.net/blog/post.aspx?id=2656a7df-9f97-4893-9c8f-c3c7732703e9</guid>
      <pubDate>Sat, 27 Mar 2010 14:42:07 -0600</pubDate>
      <category>MVC</category>
      <dc:publisher>volkanuzun</dc:publisher>
      <pingback:server>http://www.msnetprogrammer.net/blog/pingback.axd</pingback:server>
      <pingback:target>http://www.msnetprogrammer.net/blog/post.aspx?id=2656a7df-9f97-4893-9c8f-c3c7732703e9</pingback:target>
      <slash:comments>0</slash:comments>
      <trackback:ping>http://www.msnetprogrammer.net/blog/trackback.axd?id=2656a7df-9f97-4893-9c8f-c3c7732703e9</trackback:ping>
      <wfw:comment>http://www.msnetprogrammer.net/blog/post/2010/03/27/HandleError-attribute-(MVC).aspx#comment</wfw:comment>
      <wfw:commentRss>http://www.msnetprogrammer.net/blog/syndication.axd?post=2656a7df-9f97-4893-9c8f-c3c7732703e9</wfw:commentRss>
    </item>
    <item>
      <title>T4MVC</title>
      <description>&lt;p&gt;&amp;#160;&amp;#160;&amp;#160; I presented ASP.NET MVC last month at San Diego .Net User group, I think overall it was a successful presentation. I got some good comments after the presentation, and yesterday, one member of the user group asked me my demo code for the T4MVC. Unfortunately I write my demos on the fly during my presentation ( I am not afraid to write code :) ), and usually 2-3 weeks after my presentation I wipe out the virtual pc that I use for the presentation. I don’t like to turn down people, I offered him to write a simple code that utilizes T4MVC, and then writing a blog that explains T4MVC came to my mind :)&lt;/p&gt;  &lt;p&gt;While I am writing code, I am trying to avoid literal strings/magic numbers as much as possible and try to use strongly typed helpers/variables/etc instead. Obvious reasons are to have compile time support, intellisense,&amp;#160; easier maintainable code. Sometimes it is not that easy to replace the literal strings, such as if you have a link to a stylesheet, or an image source in the img tag, the strings are not easily replaced. Won’t you like the idea that the compiler will throw a compile time error when the css file is not found, or the image is not found?    &lt;br /&gt;Ex:&lt;/p&gt;  &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;link&lt;/span&gt; &lt;span class="attr"&gt;href&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;../../Content/Site.css&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;rel&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;stylesheet&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;type&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;text/css&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;style type="text/css"&gt;


.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;
  &lt;br /&gt;The above 1 line of html is taken from the sample mvc application you get, when you go File=&amp;gt;New App=&amp;gt;MVC App..&amp;#160; How are we going to replace the source of the css link with a strongly typed helper? You can do this in a few different ways, but the real easy way is to use an open source project called T4MVC.&amp;#160; You can find more information about this project at &lt;a href="http://mvccontrib.codeplex.com/wikipage?title=T4MVC_doc&amp;amp;referringTitle=T4MVC"&gt;Codeplex&lt;/a&gt;&amp;#160; &lt;br /&gt;Basically it is a T4 template that helps you to remove the magic strings from your MVC projects, and it runs on Visual Studio 2008 as well as Visual Studio 2010. As a quick example the html line above that adds the css could be converted into:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;link&lt;/span&gt; &lt;span class="attr"&gt;href&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;&amp;lt;%=Links.Content.Site_css %&amp;gt;&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;rel&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Stylesheet&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;type&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;text/css&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;style type="text/css"&gt;

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;
  &lt;br /&gt;As you can see, we remove the magic string of “../../Content/Site.css” and put a strongly typed helper. Now&amp;#160; let’s download the files from the codeplex, and work on the project that Visual Studio creates when you create a new MVC application. The next thing is drag the the files “T4MVC.settings.t4” and “T4MVC.tt” to the root of your project into the solution explorer. Visual Studio will pop up a warning: 

  &lt;br /&gt;&lt;a href="http://www.msnetprogrammer.net/blog/image.axd?picture=image_5.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.msnetprogrammer.net/blog/image.axd?picture=image_thumb_5.png" width="353" height="132" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;As these two files are script files that use using T4 template, the scripts will have full access to your project, and Visual Studio is friendly! warning. Just click OK and skip this window.&amp;#160; Even before you compile, if you check the solution explorer, there are more files generated by the T4 template.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.msnetprogrammer.net/blog/image.axd?picture=image_6.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.msnetprogrammer.net/blog/image.axd?picture=image_thumb_6.png" width="244" height="122" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;T4MVC examined your project, created a list of all the magic strings, and&amp;#160; prepared strongly typed helpers. One of the generated files is T4MVC.cs and it has 2 classes for your use in your project. Scripts and Content classes (it is not a coincidence that you have these folders in the project), both are static classes under the namespace of Links.&amp;#160; These 2 classes are full with const strings. These const strings are used to replace your magic strings in your project, and if you add more magic strings in the code, just compile the project, and T4MVC will create the new const strings too. 
  &lt;br /&gt;Now if you check the html code above one more time, you will see that we use that Links namespace, and Content class. In this Content class, T4MVC converted the magic string to a const string named Site_css.&amp;#160; &lt;/p&gt;

&lt;p&gt;Let’s assume we want to add the Jquery-1.3.2.js file to our site.master page, we could either use the old magic string way:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;script&lt;/span&gt; &lt;span class="attr"&gt;src&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;../../Scripts/jquery-1.3.2.js&amp;quot;&lt;/span&gt; 
        &lt;span class="attr"&gt;type&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;text/javascript&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;language&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;javascript&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;    &lt;/pre&gt;
&lt;style type="text/css"&gt;

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;&lt;style type="text/css"&gt;

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;
  &lt;br /&gt;or, you can use T4MVC to help us and write:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;script&lt;/span&gt; &lt;span class="attr"&gt;src&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;&amp;lt;%=Links.Scripts.jquery_1_3_2_js %&amp;gt;&amp;quot;&lt;/span&gt; 
          &lt;span class="attr"&gt;type&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;text/javascript&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;language&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;javascript&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;style type="text/css"&gt;

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;
  &lt;br /&gt;This time we used Links namespace and Scripts class, as you can notice the folder names become the class names. 

  &lt;br /&gt;To display another helper, I added a new image to this project with the name of “hour_glass.jpg”.&amp;#160; To display this image I can either use the magic strings such as: &lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;img&lt;/span&gt; &lt;span class="attr"&gt;src&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;../../Content/hour_glass.jpg&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;alt&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;style type="text/css"&gt;

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;
  &lt;br /&gt;or I can use T4MVC to and write this:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;img&lt;/span&gt; &lt;span class="attr"&gt;src&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;&amp;lt;%=Links.Content.hour_glass_jpg %&amp;gt;&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;alt&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;style type="text/css"&gt;

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;
  &lt;br /&gt;Up to now we remove the magic strings for the image and scripts, and styles, let’s see what we can do with links. In the default project, we have to links in the master page: &lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;li&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;span class="asp"&gt;&amp;lt;%&lt;/span&gt;= Html.ActionLink(&lt;span class="str"&gt;&amp;quot;Home&amp;quot;&lt;/span&gt;, &lt;span class="str"&gt;&amp;quot;Index&amp;quot;&lt;/span&gt;, &lt;span class="str"&gt;&amp;quot;Home&amp;quot;&lt;/span&gt;)&lt;span class="asp"&gt;%&amp;gt;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;li&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;li&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;span class="asp"&gt;&amp;lt;%&lt;/span&gt;= Html.ActionLink(&lt;span class="str"&gt;&amp;quot;About&amp;quot;&lt;/span&gt;, &lt;span class="str"&gt;&amp;quot;About&amp;quot;&lt;/span&gt;, &lt;span class="str"&gt;&amp;quot;Home&amp;quot;&lt;/span&gt;)&lt;span class="asp"&gt;%&amp;gt;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;li&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;style type="text/css"&gt;

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;
  &lt;br /&gt;Let’s rewrite these with T4MVC helpers:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;li&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;span class="asp"&gt;&amp;lt;%&lt;/span&gt;=Html.ActionLink(&lt;span class="str"&gt;&amp;quot;Home&amp;quot;&lt;/span&gt;,MVC.Home.Index()) &lt;span class="asp"&gt;%&amp;gt;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;li&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;li&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;span class="asp"&gt;&amp;lt;%&lt;/span&gt;=Html.ActionLink(&lt;span class="str"&gt;&amp;quot;About&amp;quot;&lt;/span&gt;,MVC.Home.About()) &lt;span class="asp"&gt;%&amp;gt;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;li&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;style type="text/css"&gt;

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;
  &lt;br /&gt;So what happened here? T4MVC created a static class called Home, (it also created the static classes for Shared, and Account), and created the function Index() which basically calls the Index action&amp;#160; of HomeController. If the Index action has a parameter such as an integer then T4MVC will generated the code accordingly; an action that has a parameter of int:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;virtual&lt;/span&gt; ActionResult Index(&lt;span class="kwrd"&gt;int&lt;/span&gt;? id)&lt;/pre&gt;
&lt;style type="text/css"&gt;

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;
  &lt;br /&gt;could be called like:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;li&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;span class="asp"&gt;&amp;lt;%&lt;/span&gt;=Html.ActionLink(&lt;span class="str"&gt;&amp;quot;Home&amp;quot;&lt;/span&gt;,MVC.Home.Index(5)) &lt;span class="asp"&gt;%&amp;gt;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;li&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;style type="text/css"&gt;

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;
  &lt;br /&gt;So far, if you changed the signature of Index(), or delete the image , or change the name of the style you will get a compile error as they are all strongly typed helpers. Also Visual Studio helps you with intellisense to fill in those magic strings. 

  &lt;br /&gt;What if we want to remove the magic strings in the controllers too? Such as in the default MVC project, if you open the admin controller Logoff action is:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;virtual&lt;/span&gt; ActionResult LogOff()
{
    FormsAuth.SignOut();
    &lt;span class="kwrd"&gt;return&lt;/span&gt; RedirectToAction(&lt;span class="str"&gt;&amp;quot;Index&amp;quot;&lt;/span&gt;, &lt;span class="str"&gt;&amp;quot;Home&amp;quot;&lt;/span&gt;);
}&lt;/pre&gt;
&lt;style type="text/css"&gt;

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;This function has a magic string of “Index” and “Home”, we can use T4MVC to change these into strongly typed helpers too such as:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;virtual&lt;/span&gt; ActionResult LogOff()
{
   FormsAuth.SignOut();
   &lt;span class="kwrd"&gt;return&lt;/span&gt; RedirectToAction(MVC.Home.Index());
}&lt;/pre&gt;
&lt;style type="text/css"&gt;

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;
  &lt;br /&gt;How about the routes in the global.asax.cs file? An example route:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;routes.MapRoute(
   &lt;span class="str"&gt;&amp;quot;Default&amp;quot;&lt;/span&gt;,                                             
   &lt;span class="str"&gt;&amp;quot;{controller}/{action}/{id}&amp;quot;&lt;/span&gt;,                          
    &lt;span class="kwrd"&gt;new&lt;/span&gt; { controller = &lt;span class="str"&gt;&amp;quot;Home&amp;quot;&lt;/span&gt;, action = &lt;span class="str"&gt;&amp;quot;Index&amp;quot;&lt;/span&gt;, id = &lt;span class="str"&gt;&amp;quot;&amp;quot;&lt;/span&gt; } 
 );&lt;/pre&gt;
&lt;style type="text/css"&gt;

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;
  &lt;br /&gt;and this is how it is replaced using T4MVC:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;routes.MapRoute(&lt;span class="str"&gt;&amp;quot;t4mvc&amp;quot;&lt;/span&gt;,
  &lt;span class="str"&gt;&amp;quot;{controller}/{action}/{id}&amp;quot;&lt;/span&gt;,
   MVC.Home.Index()
 );&lt;/pre&gt;
&lt;style type="text/css"&gt;

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;br /&gt;

&lt;p&gt;And the form we have in the Logon.aspx page of the AccountController:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="asp"&gt;&amp;lt;%&lt;/span&gt; &lt;span class="kwrd"&gt;using&lt;/span&gt; (Html.BeginForm()) { &lt;span class="asp"&gt;%&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;style type="text/css"&gt;

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;
  &lt;br /&gt;could be converted into:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="asp"&gt;&amp;lt;%&lt;/span&gt; &lt;span class="kwrd"&gt;using&lt;/span&gt; (Html.BeginForm(MVC.Account.LogOn())) { &lt;span class="asp"&gt;%&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;style type="text/css"&gt;

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;
  &lt;br /&gt;T4MVC works in routes, in views, in controllers, almost anywhere :), it has some problems too such as if you create a new folder, and add content to that folder, T4MVC won’t recognize this new folder, however it has good community support and these small items may be fixed, it also has some other support for MVC 2.0 and you can check these from its codeplex website.&lt;/p&gt;</description>
      <link>http://www.msnetprogrammer.net/blog/post/2010/03/26/T4MVC.aspx</link>
      <author>volkanuzun</author>
      <comments>http://www.msnetprogrammer.net/blog/post/2010/03/26/T4MVC.aspx#comment</comments>
      <guid>http://www.msnetprogrammer.net/blog/post.aspx?id=49182b8d-5b4f-41a1-b260-2534382efe47</guid>
      <pubDate>Fri, 26 Mar 2010 23:39:12 -0600</pubDate>
      <category>T4MVC</category>
      <dc:publisher>volkanuzun</dc:publisher>
      <pingback:server>http://www.msnetprogrammer.net/blog/pingback.axd</pingback:server>
      <pingback:target>http://www.msnetprogrammer.net/blog/post.aspx?id=49182b8d-5b4f-41a1-b260-2534382efe47</pingback:target>
      <slash:comments>4</slash:comments>
      <trackback:ping>http://www.msnetprogrammer.net/blog/trackback.axd?id=49182b8d-5b4f-41a1-b260-2534382efe47</trackback:ping>
      <wfw:comment>http://www.msnetprogrammer.net/blog/post/2010/03/26/T4MVC.aspx#comment</wfw:comment>
      <wfw:commentRss>http://www.msnetprogrammer.net/blog/syndication.axd?post=49182b8d-5b4f-41a1-b260-2534382efe47</wfw:commentRss>
    </item>
    <item>
      <title>TempData in MVC 1.0</title>
      <description>&lt;p&gt;&amp;#160;&amp;#160;&amp;#160; TempData is an interesting structure in MVC 1.0, and could be a little problematic if you don’t know the internals of it while using, so in MVC 2.0 TempData structure is changed. Today I want to analyze MVC 1.0’s TempData structure.&lt;/p&gt;  &lt;p&gt;TempData is used to store information that will be consumed only once. A good example could be some information/error messages that will be passed to the view, and if the user refreshes the page, the message will be gone. For example:&lt;/p&gt;  &lt;pre class="csharpcode"&gt;[AcceptVerbs(HttpVerbs.Post)]
&lt;span class="kwrd"&gt;public&lt;/span&gt; ActionResult Save(Order order)
{
    &lt;span class="kwrd"&gt;if&lt;/span&gt;(order.Validate()==&lt;span class="kwrd"&gt;false&lt;/span&gt;)
    {
        TempData[&lt;span class="str"&gt;&amp;quot;Msg&amp;quot;&lt;/span&gt;]=&lt;span class="str"&gt;&amp;quot;There are problems with order, please fix'em&amp;quot;&lt;/span&gt;;
        &lt;span class="kwrd"&gt;return&lt;/span&gt; RedirectToAction(&lt;span class="str"&gt;&amp;quot;ValidationError&amp;quot;&lt;/span&gt;);
    }
    &lt;span class="rem"&gt;//... some save to database action &lt;/span&gt;
   TempData[&lt;span class="str"&gt;&amp;quot;Msg&amp;quot;&lt;/span&gt;]=&lt;span class="str"&gt;&amp;quot;Your order will be shipped ASAP&amp;quot;&lt;/span&gt;;
  &lt;span class="kwrd"&gt;return&lt;/span&gt; RedirectToAction(&lt;span class="str"&gt;&amp;quot;OrderComplete&amp;quot;&lt;/span&gt;);
}&lt;/pre&gt;

&lt;p&gt;&lt;style type="text/css"&gt;





.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;&lt;/p&gt;

&lt;p&gt;As you can see in the code above, we are passing a message to one of the actions informing about the status of the order. If the user refreshes the page, TempData[“Msg”] will be cleared and the message will be gone. How does MVC 1.0 accomplish this? Basically, it stores the the value in the session, and after the roundtrip it deletes the value, but more technically:
  &lt;br /&gt;If you open the MVC source code, and go to the Controller.cs file line 100, you will see that the controller has a member called TempDataProvider which is by default a SessionStateTempDataProvider. This provider implements an interface that has the below signature:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;interface&lt;/span&gt; ITempDataProvider {
  Dictionary&amp;lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;, &lt;span class="kwrd"&gt;object&lt;/span&gt;&amp;gt; LoadTempData(ControllerContext controllerContext);
  &lt;span class="kwrd"&gt;void&lt;/span&gt; SaveTempData(ControllerContext controllerContext, &lt;br /&gt;                    IDictionary&amp;lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;, &lt;span class="kwrd"&gt;object&lt;/span&gt;&amp;gt; values);
    } &lt;/pre&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;So basically its job is to load or save a dictionary, and the SessionStateTempDataProvider is using the Session to load or save the dictionary. This dictionary is storing your temp values.&amp;#160; &lt;br /&gt;Let’s check what SessionStateTempDataProvider LoadTempData does. The first thing the provider does is to get the dictionary from the controllercontext’s session. If the session does not return a value for the dictionary (in case you haven’t used the TempData in your code , then the session value is empty), then a new Dictionary&amp;lt;string,object&amp;gt; is instantiated and returned back to the caller.

  &lt;br /&gt;If the session value has a value for the dictionary, then it is taken from the session, the session value is cleared, and dictionary is returned. After this point, there is no value for the dictionary in the session, so it is caller’s job to save the dictionary back to the session. 

  &lt;br /&gt;Here is the code from the mvc source code:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;virtual&lt;/span&gt; IDictionary&amp;lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;, &lt;span class="kwrd"&gt;object&lt;/span&gt;&amp;gt; LoadTempData(ControllerContext &lt;br /&gt;controllerContext) &lt;br /&gt;{
   HttpContextBase httpContext = controllerContext.HttpContext;
            
   &lt;span class="kwrd"&gt;if&lt;/span&gt; (httpContext.Session == &lt;span class="kwrd"&gt;null&lt;/span&gt;) {
      &lt;span class="kwrd"&gt;throw&lt;/span&gt; &lt;span class="kwrd"&gt;new&lt;/span&gt; InvalidOperationException&lt;br /&gt;              (MvcResources.SessionStateTempDataProvider_SessionStateDisabled);
   }

  Dictionary&amp;lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;, &lt;span class="kwrd"&gt;object&lt;/span&gt;&amp;gt; tempDataDictionary =&lt;br /&gt;    httpContext.Session[TempDataSessionStateKey] &lt;span class="kwrd"&gt;as&lt;/span&gt; Dictionary&amp;lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;, &lt;span class="kwrd"&gt;object&lt;/span&gt;&amp;gt;;

  &lt;span class="kwrd"&gt;if&lt;/span&gt; (tempDataDictionary != &lt;span class="kwrd"&gt;null&lt;/span&gt;) {
     &lt;span class="rem"&gt;// If we got it from Session, remove it so that no other request gets it&lt;/span&gt;
    httpContext.Session.Remove(TempDataSessionStateKey);
    &lt;span class="kwrd"&gt;return&lt;/span&gt; tempDataDictionary;
  }
  &lt;span class="kwrd"&gt;else&lt;/span&gt;{
      &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;new&lt;/span&gt; Dictionary&amp;lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;, &lt;span class="kwrd"&gt;object&lt;/span&gt;&amp;gt;(StringComparer.OrdinalIgnoreCase);
      }
}&lt;/pre&gt;
&lt;style type="text/css"&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;
  &lt;br /&gt;SaveTempData is an easy operation, just take the passed the Dictionary and save it to the controllercontext’s session.&amp;#160; So far what we have seen is just a provider that stores a dictionary to the session, and reads a dictionary from the session. How does the controller use this provider to store and load the temp values? If you open the ControllerBase.cs file and go to line 21, you will see that the ControllerBase has a public property TempData of TempDataDictionary type. One of the problem is happening in this area. This dictionary has a Load and Save public functions, that uses SessionStateTempDataProvider (by default), to save and load the values. In order to do that, it uses 2 HashSets, one for the initial keys (the values that come back with the post back), the other HashSet is either for the keys that are newly added to the Dictionary or modified keys from the initial keys. By this way, the dictionary keeps track of who is added, who is supposed to be removed, who is updated. &lt;/p&gt;

&lt;p&gt;The controller executes ExecuteCore() to invoke the action. The first line in this function is TempData.Load. This is where the controller asks the TempData dictionary to load the dictionary, and TempData dictionary uses SessionStateTempDataProvider to load the dictionary from the session. The last line of the ExecuteCore is TempData.Save which simply takes the dictionary back from the controller, uses SessionStateTempDataProvider and saves it to the session. Do not forget that the unmodified values are removed from the dictionary when the Save method is called.&lt;/p&gt;

&lt;p&gt;What are the problems with this structure? 
  &lt;br /&gt;First of all TempData by default stores the dictionary in a session, and once it is read, it cleans the session. What if the user opens a new tab right before your TempData value is read by page? Session is shared between the tabs of the same browser, so TempData may lose the data in the session. The same problem may occur when there is an ajax call to the controller, or there is a redirecttoaction. Because of these problems MVC 2.0 has fixed some issues with TempData and we will look into the source for MVC 2.0 in a later posting.&lt;/p&gt;</description>
      <link>http://www.msnetprogrammer.net/blog/post/2010/03/19/TempData-in-MVC-10.aspx</link>
      <author>volkanuzun</author>
      <comments>http://www.msnetprogrammer.net/blog/post/2010/03/19/TempData-in-MVC-10.aspx#comment</comments>
      <guid>http://www.msnetprogrammer.net/blog/post.aspx?id=e437c145-d620-4e40-aa5d-3171a78aec78</guid>
      <pubDate>Fri, 19 Mar 2010 23:40:49 -0600</pubDate>
      <category>MVC</category>
      <dc:publisher>volkanuzun</dc:publisher>
      <pingback:server>http://www.msnetprogrammer.net/blog/pingback.axd</pingback:server>
      <pingback:target>http://www.msnetprogrammer.net/blog/post.aspx?id=e437c145-d620-4e40-aa5d-3171a78aec78</pingback:target>
      <slash:comments>2</slash:comments>
      <trackback:ping>http://www.msnetprogrammer.net/blog/trackback.axd?id=e437c145-d620-4e40-aa5d-3171a78aec78</trackback:ping>
      <wfw:comment>http://www.msnetprogrammer.net/blog/post/2010/03/19/TempData-in-MVC-10.aspx#comment</wfw:comment>
      <wfw:commentRss>http://www.msnetprogrammer.net/blog/syndication.axd?post=e437c145-d620-4e40-aa5d-3171a78aec78</wfw:commentRss>
    </item>
    <item>
      <title>HashSet&lt;T&gt;</title>
      <description>&lt;p&gt;&amp;#160;&amp;#160;&amp;#160; It is been sometime I start using and enjoying HashSet as a collection in C#. Especially if you are using NHibernate as an ORM solution, you will see HashSet in one-to-many relations in your POCO objects.&amp;#160; &lt;br /&gt;HashSet&amp;lt;T&amp;gt; lives at System.Collections.Generic namespace. It is a collection of T that you can add/remove/contains etc elements but one of the most important feature of it is, having only the unique elements. So simply if you already have “1” in the collection, and try to add the same number again, it simply won’t be added to the collection. The collection is not ordered, and uses hash algorithm the complexity of add/remove/contains is O(1) (if you don’t know what it is, you can not be faster than this). Let’s work on some sample codes and check the behavior of this collection.     &lt;br /&gt;In our first application, let’s create a HashSet&amp;lt;int&amp;gt; , add some numbers and print them to the console.     &lt;br /&gt;&lt;/p&gt;  &lt;pre class="csharpcode"&gt;HashSet&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;&amp;gt;numbers = &lt;span class="kwrd"&gt;new&lt;/span&gt; HashSet&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;&amp;gt;(); numbers.Add(1); numbers.Add(3);
numbers.Add(4); numbers.Add(2);
numbers.Add(1); numbers.Add(3);

&lt;span class="kwrd"&gt;foreach&lt;/span&gt; (var number &lt;span class="kwrd"&gt;in&lt;/span&gt; numbers)
{
  Console.Out.WriteLine(&lt;span class="str"&gt;&amp;quot;{0}&amp;quot;&lt;/span&gt;,number);
}&lt;/pre&gt;

&lt;p&gt;&lt;style type="text/css"&gt;

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;&lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;In the code above, I created a HashSet&amp;lt;int&amp;gt; added the numbers, 1,3,4,2,1,3, then iterated through the collection and printed them to the console.The output is: “1,3,4,2” as the other repetitive numbers are not added to the collection. Actually Add&amp;lt;T&amp;gt;() returns a boolean value. If the value is added to the collection it returns true, else false.&amp;#160; How about when we have reference types instead of values types. This time let’s create the class “Person” with 2 simple property, and add it to the Hash collection.&lt;/p&gt;

&lt;pre class="csharpcode"&gt;Person person1 = &lt;span class="kwrd"&gt;new&lt;/span&gt; Person {ID = 1, Name = &lt;span class="str"&gt;&amp;quot;person1&amp;quot;&lt;/span&gt;};
Person person2 = &lt;span class="kwrd"&gt;new&lt;/span&gt; Person {ID = 1, Name = &lt;span class="str"&gt;&amp;quot;person1&amp;quot;&lt;/span&gt;};
Person person3 = &lt;span class="kwrd"&gt;new&lt;/span&gt; Person {ID = 2, Name = &lt;span class="str"&gt;&amp;quot;person1&amp;quot;&lt;/span&gt;};
HashSet&amp;lt;Person&amp;gt; persons = &lt;span class="kwrd"&gt;new&lt;/span&gt; HashSet&amp;lt;Person&amp;gt;();
persons.Add(person1);
persons.Add(person2);
persons.Add(person3);
&lt;span class="kwrd"&gt;foreach&lt;/span&gt; (var person &lt;span class="kwrd"&gt;in&lt;/span&gt; persons)
{
   Console.Out.WriteLine(person);
}
.....
&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; Person
{
   &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt; ID { get; set; }
   &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; Name { get; set; }
   &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; ToString()
   {
        &lt;span class="kwrd"&gt;return&lt;/span&gt; String.Format(&lt;span class="str"&gt;&amp;quot;{0}-{1}&amp;quot;&lt;/span&gt;, ID, Name);
   }
}&lt;/pre&gt;

&lt;p&gt;&lt;style type="text/css"&gt;

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;&lt;/p&gt;

&lt;p&gt;In this example I created 3 person objects, and 2 of them has the exact same values for the properties, added them to the collection, and print all of them to the console. The result is we have all 3 objects in the collection. When we called Add&amp;lt;person&amp;gt; the hash collection, checks if the value exists in the collection or not. The way it works, is, it uses the default IEqualityComparer to figure out the equality. In our sample, as we newed up all the objects, they are all different objects, so how can we change the code that, if the value of the ID fields are same, the objects are treated as the same object, and won’t be added to hash again. You may already guess the answer, we have to write an IEqualityComparer for our person object, and pass this to the hash collection. Here is the new updated code:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;Person person1 = &lt;span class="kwrd"&gt;new&lt;/span&gt; Person {ID = 1, Name = &lt;span class="str"&gt;&amp;quot;person1&amp;quot;&lt;/span&gt;};
Person person2 = &lt;span class="kwrd"&gt;new&lt;/span&gt; Person {ID = 1, Name = &lt;span class="str"&gt;&amp;quot;person1&amp;quot;&lt;/span&gt;};
Person person3 = &lt;span class="kwrd"&gt;new&lt;/span&gt; Person {ID = 2, Name = &lt;span class="str"&gt;&amp;quot;person1&amp;quot;&lt;/span&gt;};
HashSet&amp;lt;Person&amp;gt; persons = &lt;span class="kwrd"&gt;new&lt;/span&gt; HashSet&amp;lt;Person&amp;gt;(&lt;span class="kwrd"&gt;new&lt;/span&gt; PersonComparer());
persons.Add(person1);
persons.Add(person2);
persons.Add(person3);
&lt;span class="kwrd"&gt;foreach&lt;/span&gt; (var person &lt;span class="kwrd"&gt;in&lt;/span&gt; persons)
{
   Console.Out.WriteLine(person);
}
....
&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; PersonComparer:IEqualityComparer&amp;lt;Person&amp;gt;
{
   &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;bool&lt;/span&gt; Equals(Person x, Person y)
   {
       &lt;span class="kwrd"&gt;return&lt;/span&gt; x.ID == y.ID;
   }
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt; GetHashCode(Person obj)
    {
       &lt;span class="kwrd"&gt;return&lt;/span&gt; obj.ToString().GetHashCode();
     }
}
...
&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; Person
{
   &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt; ID { get; set; }
   &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; Name { get; set; }
   &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; ToString()
   {
        &lt;span class="kwrd"&gt;return&lt;/span&gt; String.Format(&lt;span class="str"&gt;&amp;quot;{0}-{1}&amp;quot;&lt;/span&gt;, ID, Name);
    }
 }&lt;/pre&gt;

&lt;p&gt;&lt;style type="text/css"&gt;

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;&lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;This way, we can still ensure that all reference typed objects are unique too in the collection. &lt;/p&gt;

&lt;p&gt;As HashSet is a set :), you can use some of the set functions too, and LINQ has 2 interesting extensions methods: Union and Intersect. Here is a sample code that uses these two extension methods:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;HashSet&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;&amp;gt; numbers1 = &lt;span class="kwrd"&gt;new&lt;/span&gt; HashSet&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;&amp;gt; {1, 2, 3, 4, 5, 6, 7};
HashSet&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;&amp;gt; numbers2 = &lt;span class="kwrd"&gt;new&lt;/span&gt; HashSet&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;&amp;gt; {10, 9, 8, 7, 6, 5, 2};

IEnumerable&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;&amp;gt;intersect = numbers1.Intersect(numbers2);
IEnumerable&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;&amp;gt; union = numbers1.Union(numbers2);&lt;/pre&gt;

&lt;p&gt;&lt;style type="text/css"&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;&lt;/p&gt;

&lt;p&gt;As you can see, HashSet is really powerful, and useful.&lt;/p&gt;</description>
      <link>http://www.msnetprogrammer.net/blog/post/2010/03/15/HashSet3cT3e.aspx</link>
      <author>volkanuzun</author>
      <comments>http://www.msnetprogrammer.net/blog/post/2010/03/15/HashSet3cT3e.aspx#comment</comments>
      <guid>http://www.msnetprogrammer.net/blog/post.aspx?id=fbc8b705-04db-46c3-b771-2a13d07d5244</guid>
      <pubDate>Mon, 15 Mar 2010 14:17:11 -0600</pubDate>
      <category>C#</category>
      <dc:publisher>volkanuzun</dc:publisher>
      <pingback:server>http://www.msnetprogrammer.net/blog/pingback.axd</pingback:server>
      <pingback:target>http://www.msnetprogrammer.net/blog/post.aspx?id=fbc8b705-04db-46c3-b771-2a13d07d5244</pingback:target>
      <slash:comments>0</slash:comments>
      <trackback:ping>http://www.msnetprogrammer.net/blog/trackback.axd?id=fbc8b705-04db-46c3-b771-2a13d07d5244</trackback:ping>
      <wfw:comment>http://www.msnetprogrammer.net/blog/post/2010/03/15/HashSet3cT3e.aspx#comment</wfw:comment>
      <wfw:commentRss>http://www.msnetprogrammer.net/blog/syndication.axd?post=fbc8b705-04db-46c3-b771-2a13d07d5244</wfw:commentRss>
    </item>
    <item>
      <title>ASP.NET Image tag and Accessibility</title>
      <description>&lt;p&gt;If you are working at a company that is following Section 508 Guidelines, and building websites that are compliant with this guidelines, you should know that asp.net image tag has a bug. Let’s start with the definition of the problem first:&lt;/p&gt;  &lt;p&gt;If you are using the images at your website purely fore decorative, then the images should have empty alt attribute such as: &amp;lt;img src=”…” alt=”” /&amp;gt;.&amp;#160; Let’s assume now that you are using &amp;lt;asp:Image control to display the decorative image such as:&lt;/p&gt;  &lt;pre class="csharpcode"&gt;&amp;lt;asp:Image id=&lt;span class="str"&gt;&amp;quot;someDecoration&amp;quot;&lt;/span&gt; runat=&lt;span class="str"&gt;&amp;quot;server&amp;quot;&lt;/span&gt; AlternateText=&lt;span class="str"&gt;&amp;quot;&amp;quot;&lt;/span&gt; ImageSrc=&lt;span class="str"&gt;&amp;quot;...&amp;quot;&lt;/span&gt;/&amp;gt;&lt;/pre&gt;

&lt;pre class="csharpcode"&gt;&amp;#160;&lt;/pre&gt;

&lt;p&gt;&lt;style type="text/css"&gt;

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;You will be suprised to see that&amp;#160; the code that this control generates is not accessible, because when the AlternateText is empty, the control does not generate the empty alt attribute but simply ignore it. If you put a space in between the quotes after the AlternateText attribute, this time screen reader will read the image alt attribute and confuse the user. 

  &lt;br /&gt;If you change the asp:Image control into html image with runat=”server attribute for whatever reason, it still has the same bug that it wont render the empty alt attribute. &lt;/p&gt;

&lt;p&gt;The solution I found for this problem is, to use alt attribute with &amp;lt;asp:Image control. The control does not recognize this attribute (asp:image control uses AlternateText to render alt attribute), and as it does not recognize the attribute, it does not touch it :). &lt;/p&gt;

&lt;p&gt;A simple hack, but works great :)&lt;/p&gt;</description>
      <link>http://www.msnetprogrammer.net/blog/post/2010/02/25/ASPNET-Image-tag-and-Accessibility.aspx</link>
      <author>volkanuzun</author>
      <comments>http://www.msnetprogrammer.net/blog/post/2010/02/25/ASPNET-Image-tag-and-Accessibility.aspx#comment</comments>
      <guid>http://www.msnetprogrammer.net/blog/post.aspx?id=dea84396-f7b9-45dc-a053-f1bb0c72a33f</guid>
      <pubDate>Thu, 25 Feb 2010 13:50:32 -0600</pubDate>
      <category>Acccessibiliy</category>
      <dc:publisher>volkanuzun</dc:publisher>
      <pingback:server>http://www.msnetprogrammer.net/blog/pingback.axd</pingback:server>
      <pingback:target>http://www.msnetprogrammer.net/blog/post.aspx?id=dea84396-f7b9-45dc-a053-f1bb0c72a33f</pingback:target>
      <slash:comments>0</slash:comments>
      <trackback:ping>http://www.msnetprogrammer.net/blog/trackback.axd?id=dea84396-f7b9-45dc-a053-f1bb0c72a33f</trackback:ping>
      <wfw:comment>http://www.msnetprogrammer.net/blog/post/2010/02/25/ASPNET-Image-tag-and-Accessibility.aspx#comment</wfw:comment>
      <wfw:commentRss>http://www.msnetprogrammer.net/blog/syndication.axd?post=dea84396-f7b9-45dc-a053-f1bb0c72a33f</wfw:commentRss>
    </item>
    <item>
      <title>What the heck is System.BadImageFormatException?</title>
      <description>&lt;p&gt;I am new to using Sqllite for my unit tests, and I was getting all bunch of errors, one of the most popular one is :&lt;/p&gt;  &lt;pre class="csharpcode"&gt;&amp;quot;System.BadImageFormatException: Could not load file or assembly &lt;br /&gt;&lt;span class="str"&gt;'System.Data.SQLite, Version=1.0.65.0, Culture=neutral,&lt;br /&gt; PublicKeyToken=db937bc2d44ff139'&lt;/span&gt; &lt;br /&gt;or one of its dependencies. An attempt was made to load a program with&lt;br /&gt;&lt;br /&gt;&lt;span class="str"&gt;Culture=neutral, PublicKeyToken=db937bc2d44ff139'&lt;/span&gt;&lt;/pre&gt;
&lt;style type="text/css"&gt;


.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;I am using Visual Studio 2010 beta 2, and Nunit for my unit tests; so most of the time I am blaming Visual Studio 2010 beta 2 version for any error I am getting, as it is a beta version! 
  &lt;br /&gt;When I googled it, I found a few different suggestions; but as in most of the Google answers, those suggested solutions work for some people apparently but not for me :). One of the suggestions actually work for me, and it is the reason for this mini blog post. Here is my information about my development environment: 

  &lt;br /&gt;I am using Resharper V5.0 beta,and Visual Studio 2010 beta 2.&amp;#160; Apperently Resharper 5.0 is running the unit tests in 32bit mode. And my development environment including the Sqllite is all 64 bits, so I need to use 64 bit version of Nunit, however Resharper is not doing this. &lt;/p&gt;

&lt;p&gt;My next step was, I ran Nunit-gui to run my unit tests, and hoped that everything was working for now, and guess what it wasn’t :). This time it was my fault,as I did not run the 64 bit of the Nunit gui. So as a next step this time I ran the Nunit-guiX64.exe and ran my tests, and everything is working fine :)&lt;/p&gt;</description>
      <link>http://www.msnetprogrammer.net/blog/post/2010/01/31/What-the-heck-is-SystemBadImageFormatException.aspx</link>
      <author>volkanuzun</author>
      <comments>http://www.msnetprogrammer.net/blog/post/2010/01/31/What-the-heck-is-SystemBadImageFormatException.aspx#comment</comments>
      <guid>http://www.msnetprogrammer.net/blog/post.aspx?id=8d2f98fd-ebce-4bde-8323-5d980628826c</guid>
      <pubDate>Sun, 31 Jan 2010 10:29:00 -0600</pubDate>
      <dc:publisher>volkanuzun</dc:publisher>
      <pingback:server>http://www.msnetprogrammer.net/blog/pingback.axd</pingback:server>
      <pingback:target>http://www.msnetprogrammer.net/blog/post.aspx?id=8d2f98fd-ebce-4bde-8323-5d980628826c</pingback:target>
      <slash:comments>0</slash:comments>
      <trackback:ping>http://www.msnetprogrammer.net/blog/trackback.axd?id=8d2f98fd-ebce-4bde-8323-5d980628826c</trackback:ping>
      <wfw:comment>http://www.msnetprogrammer.net/blog/post/2010/01/31/What-the-heck-is-SystemBadImageFormatException.aspx#comment</wfw:comment>
      <wfw:commentRss>http://www.msnetprogrammer.net/blog/syndication.axd?post=8d2f98fd-ebce-4bde-8323-5d980628826c</wfw:commentRss>
    </item>
  </channel>
</rss>