<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-4930197226974329220</id><updated>2024-09-01T00:13:47.055-07:00</updated><category term="technical"/><category term="C#"/><category term="WCF"/><category term="Advanced WCF"/><category term="Mock"/><category term="Moles"/><category term="Unit testing"/><category term="WCF C# versioning DotNet"/><category term="WCF tuning"/><category term="DotNet"/><category term="Interlocked"/><category term="Pex"/><category term="aspnet mvc"/><category term="mvc"/><category term="sql tuning"/><category term="threading"/><category term="wcf REst"/><title type='text'>! [Technical ]</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://technicalwizardry.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4930197226974329220/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://technicalwizardry.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>lloyd</name><uri>http://www.blogger.com/profile/04794204354889644869</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgA5q0xlK7umtyyBWFkMQwZQOonP5LuVNL3QnnfiZ409SLryDamMSxGdyRR_LciyL1hZR4-DjkZSY7MmTEMdAChFXno-bc9lW3Lo5xV3dYQvdK11xedJ3oJG1_C6fxBgXE/s220/IMG_0236.jpg'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>15</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-4930197226974329220.post-8087907238951048427</id><published>2016-05-02T22:34:00.000-07:00</published><updated>2016-05-02T22:34:20.562-07:00</updated><title type='text'>Interview at Amazon Bangalore</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;Some time back i had an interview with Amazon bangalore, i had to go through a telephonic round which lasted up to an hour, once i cleared that i received an email from HR stating that i need to write a snippet about my achievements either on technical or management. So i chose what i had been doing best in that last 2 years at my previous employment.&lt;br /&gt;
&lt;br /&gt;
&lt;em&gt;Instances when you adopted new innovative ideas from your team or elsewhere to improve and simplify your product/ Process. How do you quantify the benefits? What was the learning?&lt;br /&gt;
&lt;/em&gt;&lt;br /&gt;
Below is what i actually submitted to Amazon and after that i was called for a F2F interview with them.&lt;br /&gt;
&lt;br /&gt;
One of the most satisfying moments in my career was while I was at XXXX.&lt;br /&gt;
I led two mission critical and high visibility products in the YYYYY department. To give you some context the YYY product has over 450 Hospitals as a client base and run at some of the most important hospitals in the US. &lt;br /&gt;
&lt;br /&gt;
When I came into the organization, XXXX was in the end stages of porting the YYYY application to a newer technology. At the same time through the existing team we had to maintain and support the older line on an older technology. Towards the end of 2014 as the product was GA we had issues crop up from our Beta customers and we were caught up in addressing issues as soon as they came. Given the limited resources and the need to support two lines of the product it was apparent that we will soon be hitting a crunch on time and people resources.&lt;br /&gt;
&lt;br /&gt;
The first thing that I set about to optimize were the following&lt;br /&gt;
&lt;br /&gt;
 1) Sync-up meetings (Bangalore Team -- US Team)&lt;br /&gt;
 On an average the team were spending 2 hours updating their status of tasks one at beginning of the week and the other at the end of the week. So cumulatively given a team size of 15 that is a cumulative 30 hours.&lt;br /&gt;
 &lt;br /&gt;
 Why did I feel this was important?&lt;br /&gt;
  a. Breakdown in stakeholder communication &lt;br /&gt;
  b. Lack of trust. &lt;br /&gt;
  c. Effective hours spent in office&lt;br /&gt;
  d. Colleagues get frustrated.&lt;br /&gt;
  &lt;br /&gt;
      Root cause &amp; Fix&lt;br /&gt;
 Team tended to take on more tasks without understanding the depth of the problem. Also since the new product line was developed by consultants and handed over to the DEV team we were also stuck with issues coming out of regression testing. This led us to over commit based on our capacity and led to slip up on tasks.&lt;br /&gt;
 &lt;br /&gt;
 I approached this issue by including my Director in Bangalore with a plan of approach and gaining consensus so as to &lt;br /&gt;
  ○ Limit number of participants to Engineering Manager, Lead, PM, QA lead and reduce the duration and frequency&lt;br /&gt;
  ○ Setup a separate meeting that included me and counterparts in the US middle of the week to sync up on team performance&lt;br /&gt;
  ○  I worked with the team to improve the communication to key stakeholders by first breaking down the task the least possible work item and providing an better estimate.&lt;br /&gt;
  ○ Spoke to my counterparts and laid out a plan of improvement over a Q-O-Q basis and then was successful to bring this down to a half hour meeting in a week as they saw improvement in the team performance.&lt;br /&gt;
&lt;br /&gt;
 2) Service Package Quality (SP)&lt;br /&gt;
 We deliver code break fixes on a monthly basis to our customers, package quality is a metric used at XXXX which roughly calculates the number of client downloads of the SP versus the number of tickets raised against that down through support.&lt;br /&gt;
 This was one of the biggest challenge that I faced, how do I improve my teams code quality and have customer base that is raving about our quality. At the beginning of my journey with XXXX the package quality roughly stood as follows, Q3, 2013 was the timeline when I joined XXXX , this was the challenge I was faced with a worse package quality that has visibilty of all the VP at XXXXX. Towards the end of my tenure I was able to move the bar higher for the team through these slew of corrections&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi5j2nXzG2YMgGjNbSzFYU4kGTrHQIwYRuRKRVmS4-6B31wTgwBRXhMsyNr0F0XNX8SUSVPSP-awds_syY5ilBn7hf3hkX5-uxAwzurxXXTIaPJ8TPlGyDY4yOIjtiXFiX0P0FLytF9ofM/s1600/QOQ.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi5j2nXzG2YMgGjNbSzFYU4kGTrHQIwYRuRKRVmS4-6B31wTgwBRXhMsyNr0F0XNX8SUSVPSP-awds_syY5ilBn7hf3hkX5-uxAwzurxXXTIaPJ8TPlGyDY4yOIjtiXFiX0P0FLytF9ofM/s320/QOQ.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
 &lt;br /&gt;
Root Cause &amp; Fix&lt;br /&gt;
 • QA at XXXX is a separate organization all together and I realized that though there were one or two QA persons involved in testing, we cant improve our quality if QA leadership isn&#39;t behind us. We had to find a way to collaborate better and work on improving quality as a team.&lt;br /&gt;
 • Co-ordination : QA and Dev were not aligned on the nature of change, for a proposed change in code, QA wasn’t given time to align their test cases or time to write new test cases as all the estimates were given by the architect who didn’t consult with QA lead on what their estimates would be.&lt;br /&gt;
 • No formal design review meetings at engineering level. Failure to identify true impact of change.&lt;br /&gt;
 • No formal code review mechanism, though the team already had a process of using Crucible Review they were not    implementing it.&lt;br /&gt;
 • Right size the delivery items, justify with data on how many items we can fix realistically per SP.&lt;br /&gt;
 • QA team missing key testing areas&lt;br /&gt;
 • Whitebox testing issues from developers&lt;br /&gt;
 • Lead Architect and developers trust issues and breakdown in environment&lt;br /&gt;
 • No Gated check-in concept so as to catch the failure earlier&lt;br /&gt;
 • No automated unit testing frameworks used.&lt;br /&gt;
&lt;br /&gt;
Improvements made&lt;br /&gt;
 • Setup a collaborative environment working with the QA Manager and worked together with him to get QA resources behind our release, to ensure a stringent release process we started bug bash sessions, unscripted testing.&lt;br /&gt;
 • Lead from the front by driving all the meetings and code reviews. We introduced a concept that architect needs to review code along with two other engineers to be allowed to check-in and any build failures to be caught early.&lt;br /&gt;
 • Setup meeting and training with the team on identifying issues in code and how to analyze impact of change areas.&lt;br /&gt;
 • Worked with the team and their feedback on improving team environment by ensuring that any code break is not a persons fault but a fault in process that needs to be improved upon&lt;br /&gt;
 • Architect took up the challenge to setup a Jenkins box to allow us to build first on our local environment before code is checked-in to ensure we do it right the first time.&lt;br /&gt;
&lt;br /&gt;
Measurable Improvements&lt;br /&gt;
 • 20 to 30% increase in Service Package Quality numbers quarter on quarter compared to where we started in Q3 2013&lt;br /&gt;
 • 100% critical enhancement and bug-fix delivery to clients for Obligations (customer funded fixes)&lt;br /&gt;
 • Improved customer feedback and reduction in number of support tickets open&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://technicalwizardry.blogspot.com/feeds/8087907238951048427/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4930197226974329220/8087907238951048427' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4930197226974329220/posts/default/8087907238951048427'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4930197226974329220/posts/default/8087907238951048427'/><link rel='alternate' type='text/html' href='http://technicalwizardry.blogspot.com/2016/05/interview-at-amazon-bangalore.html' title='Interview at Amazon Bangalore'/><author><name>lloyd</name><uri>http://www.blogger.com/profile/04794204354889644869</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgA5q0xlK7umtyyBWFkMQwZQOonP5LuVNL3QnnfiZ409SLryDamMSxGdyRR_LciyL1hZR4-DjkZSY7MmTEMdAChFXno-bc9lW3Lo5xV3dYQvdK11xedJ3oJG1_C6fxBgXE/s220/IMG_0236.jpg'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi5j2nXzG2YMgGjNbSzFYU4kGTrHQIwYRuRKRVmS4-6B31wTgwBRXhMsyNr0F0XNX8SUSVPSP-awds_syY5ilBn7hf3hkX5-uxAwzurxXXTIaPJ8TPlGyDY4yOIjtiXFiX0P0FLytF9ofM/s72-c/QOQ.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4930197226974329220.post-4276212404942022056</id><published>2015-11-06T01:19:00.003-08:00</published><updated>2015-11-06T01:19:49.495-08:00</updated><title type='text'>Facebook behind the scenes - TAO</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;Ever wondered what the technology is behind the scenes at Facebook. Take a look at this video, it is suprisingly honest and concise.&lt;br /&gt;
Graphs and more Graphs as a data structure.&lt;br /&gt;
&lt;br /&gt;
If you are querying billions of queries having petabytes of information every second, this is what Facebook does..&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;https://www.usenix.org/conference/atc13/technical-sessions/presentation/bronson&quot;&gt;Click here to see the presentation on TAO &lt;/a&gt;&lt;br /&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://technicalwizardry.blogspot.com/feeds/4276212404942022056/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4930197226974329220/4276212404942022056' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4930197226974329220/posts/default/4276212404942022056'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4930197226974329220/posts/default/4276212404942022056'/><link rel='alternate' type='text/html' href='http://technicalwizardry.blogspot.com/2015/11/facebook-behind-scenes-tao.html' title='Facebook behind the scenes - TAO'/><author><name>lloyd</name><uri>http://www.blogger.com/profile/04794204354889644869</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgA5q0xlK7umtyyBWFkMQwZQOonP5LuVNL3QnnfiZ409SLryDamMSxGdyRR_LciyL1hZR4-DjkZSY7MmTEMdAChFXno-bc9lW3Lo5xV3dYQvdK11xedJ3oJG1_C6fxBgXE/s220/IMG_0236.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4930197226974329220.post-4821644392322029474</id><published>2013-05-02T01:42:00.002-07:00</published><updated>2013-05-02T01:43:01.276-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="WCF"/><title type='text'>WCF Handling Exceptions</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;If you are designing any complicated service where in you want to ensure that all possible requests are served, then it becomes important that there is a proper error handling strategy.&lt;br /&gt;
In one of my projects i had a retry mechanism which would try 3 times to send / process the request on certain types of errors. I have listed out the function which handles the retry mechanism&lt;br /&gt;
&lt;pre&gt;&lt;code&gt;
  public bool IsError(System.Exception ex)
  {
   bool retry = FALSE;

   if (ex is System.ServiceModel.CommunicationException)
   {
    if (ex is FaultException&lt;System.ServiceModel.ExceptionDetail&gt;)
    {
     // We get this case sometimes when connection has been closed, on next call.
     if ((ex as FaultException&lt;exceptiondetail&gt;).Detail.Type !=
      &quot;System.ObjectDisposedException&quot;)
     {
      ErrorLoger(&quot;generic fault - not retrying.&quot;, ex);
     }
    }
    else if (ex is System.ServiceModel.FaultException)
    {
     ErrorLoger(&quot;generic fault - not retrying.&quot;, ex);
    }
    else if (ex is System.ServiceModel.AddressAccessDeniedException ||
       ex is System.ServiceModel.Security.SecurityAccessDeniedException ||
       ex is System.ServiceModel.Security.SecurityNegotiationException ||
       ex is System.Security.Authentication.AuthenticationException)
    {
     ErrorLoger(&quot;Received access denied - not retrying.&quot;, ex);
    }
    else if (ex is System.ServiceModel.EndpointNotFoundException)
    {
     ErrorLoger(&quot;Endpoint was not found - not retrying.&quot;, ex);
    }
    else if (ex is System.ServiceModel.ServerTooBusyException)
    {
     ErrorLoger(&quot;Service AppPool may be down - not retrying.&quot;, ex);
    }
   }
   else if (ex is System.ObjectDisposedException)
   {
    var ode = ex as ObjectDisposedException;
    if (!ode.ObjectName.Contains(&quot;System.ServiceModel.ChannelFactory&quot;))
    {
     ErrorLoger(&quot;object disposed exception not related to channel factory.&quot;, ex);
    }
    else
    {
     ErrorLoger(&quot;Received object disposed exception related to the channel factory.&quot;, ex);
     retry = TRUE;
    }
   }
   else if (ex is System.TimeoutException || ex is System.Net.Sockets.SocketException)
   {
    if ((ex is System.TimeoutException))
    {
     ErrorLoger(&quot;Received TimeoutException. Retrying&quot;, ex);
    }
    else
    {
     ErrorLoger(&quot;Received SocketException. Retrying&quot;, ex);
    }
    retry = true;
   }
   else
   {
    ErrorLoger(&quot;General error, so not retrying.&quot;, ex);
   }
   return retry;
  }
The FaultException class belongs to the System.ServiceModel library.
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://technicalwizardry.blogspot.com/feeds/4821644392322029474/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4930197226974329220/4821644392322029474' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4930197226974329220/posts/default/4821644392322029474'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4930197226974329220/posts/default/4821644392322029474'/><link rel='alternate' type='text/html' href='http://technicalwizardry.blogspot.com/2013/05/wcf-handling-exceptions.html' title='WCF Handling Exceptions'/><author><name>lloyd</name><uri>http://www.blogger.com/profile/04794204354889644869</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgA5q0xlK7umtyyBWFkMQwZQOonP5LuVNL3QnnfiZ409SLryDamMSxGdyRR_LciyL1hZR4-DjkZSY7MmTEMdAChFXno-bc9lW3Lo5xV3dYQvdK11xedJ3oJG1_C6fxBgXE/s220/IMG_0236.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4930197226974329220.post-8902047535148353782</id><published>2013-04-30T01:52:00.000-07:00</published><updated>2013-04-30T01:53:24.621-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Advanced WCF"/><category scheme="http://www.blogger.com/atom/ns#" term="WCF"/><title type='text'>Generating an ASYNC proxy for your WCF service</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;If your WCF service supports ASYNC calls then we will need the right proxy that supports ASYNC so that the client can use that capability.&lt;br /&gt;
You have to use the Async attribute for your Interfaces.&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;&lt;code&gt;
        [OperationContractAttribute(AsyncPattern = true)]
        IAsyncResult BeginProcessStudentEnrollment(AsyncCallback callback, object asyncState);
        Result EndProcessStudentEnrollment(IAsyncResult result);
&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;
The Async pattern follows the Begin and End pairs, this internally makes use of the Async pattern in the System.IAsyncResult interface.&lt;br /&gt;
&lt;br /&gt;
In your implementation class you will have to do the following, implement both the Begin and End pairs. This is case sensitive do make sure that it follows the same as in your interface definition&lt;br /&gt;
&lt;pre&gt;&lt;code&gt;
public IAsyncResult BeginProcessStudentEnrollment(AsyncCallback callback, object asyncState)
        {
            ServerResponse response = new ServerResponse();
            try
            {             
                    long rows = GetEnrollment(); //Business Layer call
                    if (rows &gt; 0)
                    {
                        response.SetSuccessResponse(true, &quot;Successfully executed&quot;);
                    }
                    else
                    {
                        response.SetSuccessResponse(false, &quot;No records were updated&quot;);
                    }
            }
            
            catch (Exception error)
            {
              response.SetErrorResponse(500, &quot;General type exception, see service error logs for details&quot;);
            }
            return new CompletedAsyncResult&lt;serverresponse&gt;(response);
        }

        public Result EndProcessStudentEnrollment(IAsyncResult r)
        {
            CompletedAsyncResult&lt;serverresponse&gt; result = r as CompletedAsyncResult&lt;serverresponse&gt;;
            return result.Data;
        }
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;CompletedAsyncResult is the class that will handle your Response objects. I have listed this class below&lt;br /&gt;
&lt;pre&gt;&lt;code&gt;
    /// &lt;summary&gt;
    /// This class handles the completed Async calls by implementing the IAsyncResult interface.
    /// &lt;/summary&gt;
    /// &lt;typeparam name=&quot;T&quot;&gt;&lt;/typeparam&gt;
    public class CompletedAsyncResult&lt;t&gt; : IAsyncResult
    {
        T data;

        public CompletedAsyncResult(T data)
        {
            this.data = data;
        }

        public T Data
        {
            get { return data; }
        }

        #region IAsyncResult Members
        public object AsyncState
        {
            get
            {
                return (object)data;
            }
        }

        public WaitHandle AsyncWaitHandle
        {
            get
            {
                return null;
            }
        }

        public bool CompletedSynchronously
        {
            get
            {
                return true;
            }
        }

        public bool IsCompleted
        {
            get
            {
                return true;
            }
        }
        #endregion
    }
&lt;/code&gt;
&lt;/pre&gt;&lt;br /&gt;
and finally the generation of the Async aware proxy is done with this command line argument&lt;br /&gt;
&lt;br /&gt;
&lt;code&gt;svcutil http://localhost/StudentPerfService/PerfService.svc?wsdl /a /tcv:Version35&lt;/code&gt;</content><link rel='replies' type='application/atom+xml' href='http://technicalwizardry.blogspot.com/feeds/8902047535148353782/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4930197226974329220/8902047535148353782' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4930197226974329220/posts/default/8902047535148353782'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4930197226974329220/posts/default/8902047535148353782'/><link rel='alternate' type='text/html' href='http://technicalwizardry.blogspot.com/2013/04/generating-async-proxy-for-your-wcf.html' title='Generating an ASYNC proxy for your WCF service'/><author><name>lloyd</name><uri>http://www.blogger.com/profile/04794204354889644869</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgA5q0xlK7umtyyBWFkMQwZQOonP5LuVNL3QnnfiZ409SLryDamMSxGdyRR_LciyL1hZR4-DjkZSY7MmTEMdAChFXno-bc9lW3Lo5xV3dYQvdK11xedJ3oJG1_C6fxBgXE/s220/IMG_0236.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4930197226974329220.post-5170034744888574657</id><published>2013-04-29T02:19:00.000-07:00</published><updated>2013-04-29T02:19:04.319-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="C#"/><category scheme="http://www.blogger.com/atom/ns#" term="Mock"/><category scheme="http://www.blogger.com/atom/ns#" term="Moles"/><category scheme="http://www.blogger.com/atom/ns#" term="Pex"/><category scheme="http://www.blogger.com/atom/ns#" term="Unit testing"/><title type='text'>How to Mole DataReader in your Unit Tests</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;In one of my projects i had to write unit test cases around a DataReader object.&lt;br /&gt;
We have a middle tier that talks to the database and fetches the records. The middle tier then uses the C# DataReader class and populates the business layer objects.&lt;br /&gt;
&lt;br /&gt;
This example shows a Moles sample on how to do this.&lt;br /&gt;
&lt;br /&gt;
This is the DB layer class that makes the call to the Stored Procedure&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;&lt;code&gt;public List&lt;configdata&gt; GetConfiguration()
        {
            ConnectionString = connectionstring;
            List&lt;configdata&gt; configDataList = new List&lt;configdata&gt;();
            using (sqlconnection = GetDbConnection())
            {
                using (SqlCommand sqlCommand = GetDbSprocCommand(DataAccessConstants.LoadConfiguration, sqlconnection))
                {
                    if (sqlCommand != null)
                    {
                        if (sqlconnection.State != System.Data.ConnectionState.Open)
                        {
                            sqlconnection.Open();
                        }

                        &lt;b&gt;SqlDataReader dr = sqlCommand.ExecuteReader();&lt;/b&gt;
                        ConfigData configdata;
                        while (dr.Read())
                        {
                            configdata = new ConfigData();
                            configdata.ConfigKeyName = dr[0].ToString();
                            configdata.ConfigKeyValue = dr[1].ToString();
                            configDataList.Add(configdata);
                        }
                        dr.Close();
                    }
                }
            }
            return configDataList;
        }
&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;
I now want to Mole out the SQLDATAReader in the code above. Since the SqlCommand is a C# native library i cannot Stub it out , so i Mole out that library by right clicking in the References and choosing &#39;Mole it&#39; in the options that come up. &lt;br /&gt;
The idea is that i need to unit test the whole While loop above because the SQL Database is mocked we need to ensure that the test case passes in the while loop.&lt;br /&gt;
&lt;br /&gt;
Listed below is how i moled out the DataReader class&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;&lt;code&gt;
public void Sanity_Test()
        {

            MSqlConnection.AllInstances.Open = (c) =&gt; { };
            MSqlConnection.AllInstances.Close = (c) =&gt; { };
         
            int readCount = 0;
            object[] data = { &quot;STRING_NAME1&quot;, &quot;y&quot;, &quot;STRING_Name2&quot;, &quot;n&quot;, &quot;String_Name3&quot;, &quot;ValuesAre&quot; };
            //Create a delegate the simulates result in the record 
            MSqlCommand.AllInstances.ExecuteReader = (SqlCommand cmd) =&gt;
            {
                MSqlDataReader x = new MSqlDataReader();
                x.Read = () =&gt; readCount++ == 0;
                x.ItemGetInt32 = index =&gt; data[index];
                return x;
            };

            MSqlDataReader.AllInstances.Read = (a) =&gt; { return false; };
            
            //Also create a delegate for the DataReader close 
            MSqlDataReader.AllInstances.Close = (a) =&gt; { };

            MySpecialClass rep = new MySpecialClass();
            var result = rep.GetConfigurationValues();
            if (null != result)
            {
                Assert.AreEqual(result[0].ConfigKeyName,&quot;STRING_NAME1&quot;);
            }
        }
&lt;/code&gt;
&lt;/pre&gt;&lt;br /&gt;
By creating the Object [] Array and then by mocking the Execute reader class as shown above i am able to do it.&lt;br /&gt;
The trick is to use the following lines&lt;br /&gt;
                MSqlDataReader x = new MSqlDataReader();&lt;br /&gt;
                x.Read = () =&gt; readCount++ == 0;&lt;br /&gt;
                x.ItemGetInt32 = index =&gt; data[index];&lt;br /&gt;
                return x;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://technicalwizardry.blogspot.com/feeds/5170034744888574657/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4930197226974329220/5170034744888574657' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4930197226974329220/posts/default/5170034744888574657'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4930197226974329220/posts/default/5170034744888574657'/><link rel='alternate' type='text/html' href='http://technicalwizardry.blogspot.com/2013/04/how-to-mole-datareader-in-your-unit.html' title='How to Mole DataReader in your Unit Tests'/><author><name>lloyd</name><uri>http://www.blogger.com/profile/04794204354889644869</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgA5q0xlK7umtyyBWFkMQwZQOonP5LuVNL3QnnfiZ409SLryDamMSxGdyRR_LciyL1hZR4-DjkZSY7MmTEMdAChFXno-bc9lW3Lo5xV3dYQvdK11xedJ3oJG1_C6fxBgXE/s220/IMG_0236.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4930197226974329220.post-6116633887442088670</id><published>2013-04-29T01:25:00.000-07:00</published><updated>2013-04-29T01:30:08.230-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="C#"/><category scheme="http://www.blogger.com/atom/ns#" term="DotNet"/><category scheme="http://www.blogger.com/atom/ns#" term="Mock"/><category scheme="http://www.blogger.com/atom/ns#" term="Moles"/><category scheme="http://www.blogger.com/atom/ns#" term="Unit testing"/><title type='text'>Dot NET unit testing frameworks</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;Unit testing is defined as Testing the smallest unit of work. What that means is to test your functions independent of dependent functions. This kind of testing will just test one part of the function independent of other dependents. &lt;br /&gt;
If the module is dependent on an external source we will need to make a Mock or in other words generate a proxy for that class. This way we only test the function that we are interested in.&lt;br /&gt;
&lt;br /&gt;
Unit tests are generally done to get code coverage stats which show how much of the code is covered by the test case. Whether all the conditional statements, Error handling conditions are tested.&lt;br /&gt;
&lt;br /&gt;
It has wide acceptance in TDD methodology, unit tests are created before code is written. The unit tests are&amp;nbsp;executed against the function frequently.&amp;nbsp;As code&amp;nbsp;is developed further either, code is changed or via an automated process with the build. If the unit tests fail, it is considered to be a bug either in the changed code or the tests themselves. &lt;br /&gt;
&lt;br /&gt;
There are a lot of Mocking Frameworks out there, There are essentially two different types of mocking frameworks, one that are implemented via dynamic proxy and another one that are implemented via CLR profiler API. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;&lt;span class=&quot;mw-headline&quot; id=&quot;Proxy_based_mocking_frameworks&quot;&gt;Proxy based mocking frameworks&lt;/span&gt;&lt;/h3&gt;&lt;p&gt;Proxy based mocking frameworks uses reflection and runtime code generation to dynamically generate classes (proxies) that either implement an interface being mocked or derive from a non-sealed class that’s being mocked.  &lt;br /&gt;
This can be used only when good OO principles and dependency injection container been utilized for building the system (i.e. loose coupling, high cohesion and utilizes interfaces heavily) &lt;br /&gt;
&lt;/p&gt;&lt;p&gt;A proxy object is an object that is used to take the place of a real object. In the case of mock objects, a proxy object is used to imitate the real object your code is dependent on. We can create a proxy object with any of below available proxy based mocking frameworks.&lt;br /&gt;
&lt;/p&gt;&lt;ul&gt;&lt;li&gt; &lt;a rel=&quot;nofollow&quot; class=&quot;external text&quot; href=&quot;http://code.google.com/p/moq/&quot;&gt;Moq &lt;/a&gt;&lt;br /&gt;
&lt;/li&gt;
&lt;/ul&gt;&lt;ul&gt;&lt;li&gt; &lt;a rel=&quot;nofollow&quot; class=&quot;external text&quot; href=&quot;http://nsubstitute.github.com/help/getting-started/&quot;&gt;NSubstitue&lt;/a&gt; &lt;br /&gt;
&lt;/li&gt;
&lt;/ul&gt;&lt;ul&gt;&lt;li&gt; &lt;a rel=&quot;nofollow&quot; class=&quot;external text&quot; href=&quot;http://hibernatingrhinos.com/open-source/rhino-mocks&quot;&gt;Rhino mocks&lt;/a&gt; &lt;br /&gt;
&lt;/li&gt;
&lt;/ul&gt;&lt;ul&gt;&lt;li&gt; &lt;a rel=&quot;nofollow&quot; class=&quot;external text&quot; href=&quot;http://code.google.com/p/fakeiteasy/&quot;&gt;FakeItEasy&lt;/a&gt;&lt;br /&gt;
&lt;/li&gt;
&lt;/ul&gt;&lt;ul&gt;&lt;li&gt; &lt;a rel=&quot;nofollow&quot; class=&quot;external text&quot; href=&quot;http://www.nmock.org/&quot;&gt;NMock&lt;/a&gt; &lt;br /&gt;
&lt;/li&gt;
&lt;/ul&gt;&lt;ul&gt;&lt;li&gt; &lt;a rel=&quot;nofollow&quot; class=&quot;external text&quot; href=&quot;http://sourceforge.net/projects/easymocknet/&quot;&gt;EasyMock&lt;/a&gt; &lt;br /&gt;
&lt;/li&gt;
&lt;/ul&gt;&lt;ul&gt;&lt;li&gt; &lt;a rel=&quot;nofollow&quot; class=&quot;external text&quot; href=&quot;http://simpledotnet.codeplex.com/&quot;&gt;Simple.NET&lt;/a&gt; &lt;br /&gt;
&lt;/li&gt;
&lt;/ul&gt;&lt;ul&gt;&lt;li&gt; &lt;a rel=&quot;nofollow&quot; class=&quot;external text&quot; href=&quot;http://nunit.org/&quot;&gt;NUnit.Mocks&lt;/a&gt; &lt;br /&gt;
&lt;/li&gt;
&lt;/ul&gt;&lt;h4&gt;&lt;span class=&quot;mw-headline&quot; id=&quot;Pros_and_Cons&quot;&gt;Pros and Cons&lt;/span&gt;&lt;/h4&gt;&lt;p&gt;&lt;b&gt;Pros&lt;/b&gt;&lt;br /&gt;
&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Open source and free &lt;br /&gt;
&lt;/li&gt;
&lt;li&gt;Can mock both non-sealed classes and interfaces&lt;br /&gt;
&lt;/li&gt;
&lt;li&gt;Type safe &lt;br /&gt;
&lt;/li&gt;
&lt;li&gt;Expressive and easy-to-learn syntax &lt;br /&gt;
&lt;/li&gt;
&lt;li&gt;Easy-to-use &lt;br /&gt;
&lt;/li&gt;
&lt;li&gt;Performance/Speed  &lt;br /&gt;
&lt;/li&gt;
&lt;/ul&gt;&lt;p&gt;&lt;b&gt;Cons&lt;/b&gt;&lt;br /&gt;
&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Heavily relies on dependency injection pattern&lt;br /&gt;
&lt;/li&gt;
&lt;li&gt;Cannot mock non-virtual, non-abstract and static methods&lt;br /&gt;
&lt;/li&gt;
&lt;li&gt;Cannot mock sealed classes and private classes&lt;br /&gt;
&lt;/li&gt;
&lt;li&gt;Backward compatibility&lt;br /&gt;
&lt;/li&gt;
&lt;li&gt;Limited technical support and community&lt;br /&gt;
&lt;/li&gt;
&lt;li&gt;Limite documentation&lt;br /&gt;
&lt;/li&gt;
&lt;/ul&gt;&lt;h3&gt;&lt;span class=&quot;mw-headline&quot; id=&quot;Profiler_based_Mocking_frameworks&quot;&gt;Profiler based Mocking frameworks&lt;/span&gt;&lt;/h3&gt;&lt;p&gt;Profiler based mocking frameworks uses the CLR profiler API’s to intercept and redirect calls to any method of any type. This makes it capable of mocking sealed types, system classes and even intercept and divert calls to non-virtual methods of concrete types. &lt;br /&gt;
&lt;/p&gt;&lt;p&gt;In general, Proxy based frameworks require that your mocks implement an interface. But what do you do when the class you are trying to mock is static or sealed with no interface. If you can’t modify the class then your unit testing efforts are usually stuck.  In that case, Profiler based mocking frameworks are generally better for developers wanting to use them on existing legacy code since it may not possible to refractor such into a design that is more testable.&lt;br /&gt;
&lt;/p&gt;&lt;p&gt;Here is the list of profiler based mocking frameworks. &lt;br /&gt;
&lt;/p&gt;&lt;ul&gt;&lt;li&gt; &lt;a rel=&quot;nofollow&quot; class=&quot;external text&quot; href=&quot;http://research.microsoft.com/en-us/projects/moles/&quot;&gt;Moles Framework&lt;/a&gt;  (from Microsoft) – Free&lt;br /&gt;
&lt;/li&gt;
&lt;/ul&gt;&lt;ul&gt;&lt;li&gt; &lt;a rel=&quot;nofollow&quot; class=&quot;external text&quot; href=&quot;http://www.typemock.com/&quot;&gt;TypeMock Isolator&lt;/a&gt; – Commercial/Paid&lt;br /&gt;
&lt;/li&gt;
&lt;/ul&gt;&lt;ul&gt;&lt;li&gt; &lt;a rel=&quot;nofollow&quot; class=&quot;external text&quot; href=&quot;http://www.telerik.com/products/mocking.aspx&quot;&gt;JustMock&lt;/a&gt; – Commercial / Paid&lt;br /&gt;
&lt;/li&gt;
&lt;/ul&gt;&lt;h4&gt;&lt;span class=&quot;mw-headline&quot; id=&quot;Pros_and_Cons_2&quot;&gt;Pros and Cons&lt;/span&gt;&lt;/h4&gt;&lt;p&gt;&lt;b&gt;Pros&lt;/b&gt;&lt;br /&gt;
&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Doesn’t rely on dependency injection pattern&lt;br /&gt;
&lt;/li&gt;
&lt;li&gt;Can mock anything including&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;Non-virtual, non-abstract and static methods&lt;br /&gt;
&lt;/li&gt;
&lt;li&gt;Sealed and private classes&lt;br /&gt;
&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;Type safe&lt;br /&gt;
&lt;/li&gt;
&lt;li&gt;Expressive and easy-to-learn syntax&lt;br /&gt;
&lt;/li&gt;
&lt;li&gt;Community &amp;amp; technical support and documentation&lt;br /&gt;
&lt;/li&gt;
&lt;li&gt;Backward compatibility&lt;br /&gt;
&lt;/li&gt;
&lt;/ul&gt;&lt;p&gt;&lt;b&gt;Cons&lt;/b&gt;&lt;br /&gt;
&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Not open source&lt;br /&gt;
&lt;/li&gt;
&lt;li&gt;Performance – profiler’s uses runtime instrumentation under the hood &lt;br /&gt;
&lt;/li&gt;
&lt;li&gt;Not easy-to-use when compared with proxy based mocking frameworks&lt;br /&gt;
&lt;/li&gt;
&lt;/ul&gt;&lt;h2&gt;&lt;span class=&quot;mw-headline&quot; id=&quot;Recommended_Mocking_Frameworks&quot;&gt;Recommended Mocking Frameworks&lt;/span&gt;&lt;/h2&gt;&lt;p&gt;Following are the recommended mocking frameworks based on above factors and external links.&lt;br /&gt;
&lt;/p&gt;&lt;h3&gt;&lt;span class=&quot;mw-headline&quot; id=&quot;Moles_Framework&quot;&gt;Moles Framework &lt;/span&gt;&lt;/h3&gt;&lt;p&gt;Moles Framework is a light weight CLR profiler based framework for test stubs and detours for .NET that is based on delegates. &lt;br /&gt;
&lt;/p&gt;&lt;p&gt;This Framework actually supports two different kinds of substitution class – stub types and mole types. These two approaches allow you to create substitute classes for code dependencies under different circumstances.&lt;br /&gt;
&lt;/p&gt;&lt;p&gt;&lt;b&gt;1. Stub types&lt;/b&gt; – Provide a lightweight isolation framework that generates fake stub implementation of virtual methods, interfaces for unit testing. For every stubbed interface and class, code is generated at compile time i.e. one stub class per interface and class. &lt;br /&gt;
&lt;/p&gt;&lt;p&gt;&lt;b&gt;2. Mole types&lt;/b&gt; - use a powerful detouring framework that uses code profiler APIs to intercept calls to dependency classes and redirects the calls to a fake object. It is used to detour any .NET method, including non-virtual and static methods in sealed types.&lt;br /&gt;
&lt;/p&gt;&lt;h4&gt;&lt;span class=&quot;mw-headline&quot; id=&quot;Pros_and_Cons_3&quot;&gt;Pros and Cons&lt;/span&gt;&lt;/h4&gt;&lt;p&gt;&lt;b&gt;Pros&lt;/b&gt;&lt;br /&gt;
&lt;/p&gt;&lt;ul&gt;&lt;li&gt;It&#39;s from Microsoft&lt;br /&gt;
&lt;/li&gt;
&lt;li&gt;Support legacy code&lt;br /&gt;
&lt;/li&gt;
&lt;li&gt;Can mock any type of object that includes from .NET library&lt;br /&gt;
&lt;/li&gt;
&lt;/ul&gt;&lt;p&gt;&lt;b&gt;Cons&lt;/b&gt;&lt;br /&gt;
&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Mole types would be quite hefty performance impact because it uses runtime instrumentation under the hood. &lt;br /&gt;
&lt;/li&gt;
&lt;li&gt;Need to regenerate the Moles assemblies each time when there is any method signature change in the system.&lt;br /&gt;
&lt;/ul&gt;&lt;h3&gt;&lt;span class=&quot;mw-headline&quot; id=&quot;Moq&quot;&gt;Moq &lt;/span&gt;&lt;/h3&gt;&lt;p&gt;Moq is the simplest proxy based mocking framework which takes advantages of the .NET 3.5 language features like lambda expression trees and C# 3.0 features like lambda expressions that make it the most productive, type-safe and refactoring-friendly mocking library available. And it supports mocking interfaces as well as classes. Its API is extremely simple and straightforward, and doesn&#39;t require any prior knowledge or experience with mocking concepts. &lt;/p&gt;&lt;h4&gt;&lt;span class=&quot;mw-headline&quot; id=&quot;Pros_and_Cons_4&quot;&gt;Pros and Cons&lt;/span&gt;&lt;/h4&gt;&lt;p&gt;&lt;b&gt;Pros&lt;/b&gt; &lt;/p&gt;&lt;ul&gt;&lt;li&gt; Very much popular&lt;br /&gt;
&lt;/li&gt;
&lt;li&gt; Strong technical support and community &lt;br /&gt;
&lt;/li&gt;
&lt;/ul&gt;&lt;p&gt;&lt;b&gt;Cons&lt;/b&gt; &lt;/p&gt;&lt;ul&gt;&lt;li&gt; Support .NET runtime 3.5 and above only &lt;br /&gt;
&lt;/li&gt;
&lt;li&gt; Difficult to mock static classes and sealed types (Code refactoring is required for legacy code)  &lt;br /&gt;
&lt;/li&gt;
&lt;li&gt; Need to use &quot;mock.Object&quot; property if we pass the mocked interface/ class over&lt;br /&gt;
&lt;/li&gt;
&lt;/ul&gt;&lt;h3&gt;&lt;span class=&quot;mw-headline&quot; id=&quot;NSubstitute&quot;&gt;NSubstitute&lt;/span&gt;&lt;/h3&gt;&lt;p&gt;NSubstitute is a friendly substitute for mocking frameworks which is a proxy based and makes use of extension methods on object for its API. And it is designed for Arrange-Act-Assert (AAA) testing, so you just need to arrange how it should work, then assert it received the calls you expected once you&#39;re done.  &lt;/p&gt;&lt;h4&gt;&lt;span class=&quot;mw-headline&quot; id=&quot;Pros_and_Cons_5&quot;&gt;Pros and Cons&lt;/span&gt;&lt;/h4&gt;&lt;p&gt;&lt;b&gt;Pros&lt;/b&gt; &lt;/p&gt;&lt;ul&gt;&lt;li&gt; Simple syntax compared to Moq &lt;br /&gt;
&lt;/li&gt;
&lt;li&gt; No need to use lambdas to set return values for a mocked property. Hence improves readability.&lt;br /&gt;
&lt;/li&gt;
&lt;li&gt; Better internal error messages compared to Moq&lt;br /&gt;
&lt;/li&gt;
&lt;/ul&gt;&lt;p&gt;&lt;b&gt;Cons&lt;/b&gt; &lt;/p&gt;&lt;ul&gt;&lt;li&gt; Difficult to mock static classes and sealed types (Code refactoring is required for legacy code)   &lt;br /&gt;
&lt;/li&gt;
&lt;li&gt; Relatively new framework compared to Moq&lt;br /&gt;
&lt;/li&gt;
&lt;li&gt; Minimal technical support and community&lt;br /&gt;
&lt;/li&gt;
&lt;/ul&gt;
I highly recommend reading this article. It has some good insights like Unit testing isn&#39;t about finding bugs :)
&lt;a href=&quot;http://blog.stevensanderson.com/2009/08/24/writing-great-unit-tests-best-and-worst-practises/&quot;&gt;Unit Test the right way&lt;/a&gt;

&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://technicalwizardry.blogspot.com/feeds/6116633887442088670/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4930197226974329220/6116633887442088670' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4930197226974329220/posts/default/6116633887442088670'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4930197226974329220/posts/default/6116633887442088670'/><link rel='alternate' type='text/html' href='http://technicalwizardry.blogspot.com/2013/04/dot-net-unit-testing-frameworks.html' title='Dot NET unit testing frameworks'/><author><name>lloyd</name><uri>http://www.blogger.com/profile/04794204354889644869</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgA5q0xlK7umtyyBWFkMQwZQOonP5LuVNL3QnnfiZ409SLryDamMSxGdyRR_LciyL1hZR4-DjkZSY7MmTEMdAChFXno-bc9lW3Lo5xV3dYQvdK11xedJ3oJG1_C6fxBgXE/s220/IMG_0236.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4930197226974329220.post-2794361809076799855</id><published>2013-04-19T02:19:00.002-07:00</published><updated>2013-04-19T02:20:34.856-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Advanced WCF"/><category scheme="http://www.blogger.com/atom/ns#" term="WCF"/><category scheme="http://www.blogger.com/atom/ns#" term="wcf REst"/><title type='text'>WCF REST service hosted on IIS 5</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;/div&gt;
Making your WCF service as RESTful is pretty simple in DOTNET. You have three options Get,Post and Put. To this you have to label your contract with an attribute something like below.&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas; font-size: x-small;&quot;&gt;&lt;span style=&quot;font-family: Consolas; font-size: x-small;&quot;&gt;[&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #2b91af; font-family: Consolas; font-size: x-small;&quot;&gt;&lt;span style=&quot;color: #2b91af; font-family: Consolas; font-size: x-small;&quot;&gt;&lt;span style=&quot;color: #2b91af; font-family: Consolas; font-size: x-small;&quot;&gt;WebGet&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: x-small;&quot;&gt;&lt;span style=&quot;font-family: Consolas; font-size: x-small;&quot;&gt;(UriTemplate = &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #a31515; font-family: Consolas; font-size: x-small;&quot;&gt;&lt;span style=&quot;color: #a31515; font-family: Consolas; font-size: x-small;&quot;&gt;&lt;span style=&quot;color: #a31515; font-family: Consolas; font-size: x-small;&quot;&gt;&quot;/StartProcessing&quot;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: x-small;&quot;&gt;&lt;span style=&quot;font-family: Consolas; font-size: x-small;&quot;&gt;)]&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Consolas; font-size: x-small;&quot;&gt;&lt;span style=&quot;font-family: Consolas; font-size: x-small;&quot;&gt;[&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #2b91af; font-family: Consolas; font-size: x-small;&quot;&gt;&lt;span style=&quot;color: #2b91af; font-family: Consolas; font-size: x-small;&quot;&gt;&lt;span style=&quot;color: #2b91af; font-family: Consolas; font-size: x-small;&quot;&gt;WebInvoke&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: x-small;&quot;&gt;&lt;span style=&quot;font-family: Consolas; font-size: x-small;&quot;&gt;(Method = &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #a31515; font-family: Consolas; font-size: x-small;&quot;&gt;&lt;span style=&quot;color: #a31515; font-family: Consolas; font-size: x-small;&quot;&gt;&lt;span style=&quot;color: #a31515; font-family: Consolas; font-size: x-small;&quot;&gt;&quot;POST&quot;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: x-small;&quot;&gt;&lt;span style=&quot;font-family: Consolas; font-size: x-small;&quot;&gt;, UriTemplate = &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #a31515; font-family: Consolas; font-size: x-small;&quot;&gt;&lt;span style=&quot;color: #a31515; font-family: Consolas; font-size: x-small;&quot;&gt;&lt;span style=&quot;color: #a31515; font-family: Consolas; font-size: x-small;&quot;&gt;&quot;/SyncCustomerDetails&quot;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: x-small;&quot;&gt;&lt;span style=&quot;font-family: Consolas; font-size: x-small;&quot;&gt;, BodyStyle = &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #2b91af; font-family: Consolas; font-size: x-small;&quot;&gt;&lt;span style=&quot;color: #2b91af; font-family: Consolas; font-size: x-small;&quot;&gt;&lt;span style=&quot;color: #2b91af; font-family: Consolas; font-size: x-small;&quot;&gt;WebMessageBodyStyle&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: x-small;&quot;&gt;&lt;span style=&quot;font-family: Consolas; font-size: x-small;&quot;&gt;.WrappedRequest)]&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &lt;br /&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;When i was working on my local development&amp;nbsp;environment which had IIS 7.5 everything went fine and i was able to access the REST based services. &lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;The problem started when i wanted to deploy this to our Development lab which has IIS 5. After it was deployed i could not even access the WCF Rest Help page, this can be accessed by appending a /help after your SVC file in the browser.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;The error returned was something Like Http 403 error saying bad request and clicking on the help link below would also throw this error. Searching on the internet did not provide with much help.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;Only one link that i found mentioned that this problem is with IIS 5 and that it does not allow accessing URL that are extension-less. To solve this some websites said to allow the &#39;*&#39; as a rule, strange this is that IIS 5 will not allow you to even put in such a parameter.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;Next suggestion i tried was to add the &#39;*&#39; in the wild card application map&amp;nbsp;extension for the website / virtual directory. To do this, i had to right click the website -&amp;gt; properties -&amp;gt; Virtual Directory Tab -&amp;gt; click on configuration.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;In the application configuration tab that comes up, press the insert button and map to aspnet_isapi dll and remove the &quot;Verify this file&quot; exists.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;Sad to say even this option did not work out.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;The thing that worked for me was this. &lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;My site is configured to run on AspNet 4.0, and the problem was that the Application Pool was configured to run on AspNet 4.0 but the account under which it runs did not have access to C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;The error that was returned also did not provide any help to this because there were no errors in IIS logs, no errors in event viewer, so it really side tracked this.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;I hope someone out there finds this useful and can save some time by trying these steps.&lt;/span&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://technicalwizardry.blogspot.com/feeds/2794361809076799855/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4930197226974329220/2794361809076799855' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4930197226974329220/posts/default/2794361809076799855'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4930197226974329220/posts/default/2794361809076799855'/><link rel='alternate' type='text/html' href='http://technicalwizardry.blogspot.com/2013/04/wcf-rest-service-hosted-on-iis-5.html' title='WCF REST service hosted on IIS 5'/><author><name>lloyd</name><uri>http://www.blogger.com/profile/04794204354889644869</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgA5q0xlK7umtyyBWFkMQwZQOonP5LuVNL3QnnfiZ409SLryDamMSxGdyRR_LciyL1hZR4-DjkZSY7MmTEMdAChFXno-bc9lW3Lo5xV3dYQvdK11xedJ3oJG1_C6fxBgXE/s220/IMG_0236.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4930197226974329220.post-9687380775135875</id><published>2013-04-03T00:24:00.000-07:00</published><updated>2013-04-03T00:29:14.367-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Advanced WCF"/><category scheme="http://www.blogger.com/atom/ns#" term="C#"/><category scheme="http://www.blogger.com/atom/ns#" term="technical"/><category scheme="http://www.blogger.com/atom/ns#" term="WCF"/><category scheme="http://www.blogger.com/atom/ns#" term="WCF C# versioning DotNet"/><category scheme="http://www.blogger.com/atom/ns#" term="WCF tuning"/><title type='text'>How to do Versioning in WCF</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;h3&gt;
&lt;span class=&quot;mw-headline&quot; id=&quot;Overview&quot;&gt;Overview&lt;/span&gt;&lt;/h3&gt;
After initial deployment, and potentially several times during their lifetime, services (and the endpoints they expose) may need to be changed for a variety of reasons, such as changes in data contracts, operations, and end point addresses. The following diagram and sections describe how these changes would lead to breaking /non-breaking changes and the action to be taken accordingly.&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;div class=&quot;thumb tnone&quot;&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a class=&quot;image&quot; href=&quot;http://www.blogger.com/tgtwiki/index.php/File:Versioning_Decision_Tree.JPG&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;thumbinner&quot; style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none; width: 860px;&quot;&gt;
&lt;div style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;thumbcaption&quot;&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhzijTXCjIyr36_6Rh-_0kTNYwKWg8KxxCJSPCpwjrl1OVakf1DgON_vdYq3QNwSvvUiRBYiftqaT7Id6uv5-wmS6ZYEoPBiAnSLbaJxTPEj-K8ugITM5UqnFL9hphLz1fpLi_8J6DN0og/s1600/Versioning_Decision_Tree.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;240&quot; mta=&quot;true&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhzijTXCjIyr36_6Rh-_0kTNYwKWg8KxxCJSPCpwjrl1OVakf1DgON_vdYq3QNwSvvUiRBYiftqaT7Id6uv5-wmS6ZYEoPBiAnSLbaJxTPEj-K8ugITM5UqnFL9hphLz1fpLi_8J6DN0og/s320/Versioning_Decision_Tree.jpg&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
Fig 1.Versioning Decision Tree&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;
The decision tree above shows you what you will need to do to handle every case and it also shows the consequences of each versioning choice you might make. The decisions include changes in the service operations, data contract, and bindings.&lt;/div&gt;
&lt;h2 style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;
&lt;span class=&quot;mw-headline&quot; id=&quot;Process_Flow_in_Versioning&quot;&gt;Process Flow in Versioning&lt;/span&gt;&lt;/h2&gt;
&lt;h3 style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;
&lt;span class=&quot;mw-headline&quot; id=&quot;Adding_and_Removing_Data_Members&quot;&gt;Adding and Removing Data Members&lt;/span&gt;&lt;/h3&gt;
&lt;div style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;
In most cases, adding or removing a data member is not a breaking change, unless you require strict schema validity (new instances validating against the old schema). &lt;/div&gt;
When a type with an extra field is deserialized into a type with a missing field, the extra information is ignored. (It may also be stored for round-tripping purposes; for more information, see &lt;a class=&quot;external text&quot; href=&quot;http://msdn.microsoft.com/en-us/library/ms731083.aspx&quot; rel=&quot;nofollow&quot;&gt;Forward-Compatible Data Contracts&lt;/a&gt;).&lt;br /&gt;
When a type with a missing field is deserialized into a type with an extra field, the extra field is left at its default value, usually zero, or null. (The default value may be changed; for more information, see &lt;a class=&quot;external text&quot; href=&quot;http://msdn.microsoft.com/en-us/library/ms733734.aspx&quot; rel=&quot;nofollow&quot;&gt;Version-Tolerant Serialization Callbacks&lt;/a&gt;.)&lt;br /&gt;
For example, you can use the CarV1 class on a client and the CarV2 class on a service, or you can use the CarV1 class on a service and the CarV2 class on a client:&lt;br /&gt;
&lt;pre style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt; // Version 1 of a data contract, on machine V1.
[DataContract(Name = &quot;Car&quot;)]
public class CarV1
{
    [DataMember]
    private string Model;
}
 
// Version 2 of the same data contract, on machine V2.
[DataContract(Name = &quot;Car&quot;)]
public class CarV2
{
    [DataMember]
    private string Model;
 
    [DataMember]
    private int HorsePower;
}
&lt;/pre&gt;
The version 2 endpoint can successfully send data to the version 1 endpoint. Serializing version 2 of the Car data contract yields XML similar to the following.&lt;br /&gt;
&lt;pre&gt;[javascript:CopyCode(&#39;ctl00_rs1_mainContentContainer_ctl15other&#39;); Copy Code]
&amp;lt;Car&amp;gt;
    &amp;lt;Model&amp;gt;Porsche&amp;lt;/Model&amp;gt;
    &amp;lt;HorsePower&amp;gt;300&amp;lt;/HorsePower&amp;gt;
&amp;lt;/Car&amp;gt;
&lt;/pre&gt;
The deserialization engine on V1 does not find a matching data member for the HorsePower field, and discards that data.&lt;br /&gt;
Also, the version 1 endpoint can send data to the version 2 endpoint. &lt;br /&gt;
The version 2 deserializer does not know what to set the HorsePower field to, because there is no matching data in the incoming XML. Instead, the field is set to the default value of 0.&lt;br /&gt;
&lt;h3&gt;
&lt;span class=&quot;mw-headline&quot; id=&quot;Required_Data_Members&quot;&gt;Required Data Members&lt;/span&gt;&lt;/h3&gt;
A data member may be marked as being required by setting the “IsRequired” property of the DataMemberAttribute to true. If required data is missing while deserializing, an exception is thrown instead of setting the data member to its default value.&lt;br /&gt;
Adding a required data member is a breaking change. That is, the newer type can still be sent to endpoints with the older type, but not the other way around. Removing a data member that was marked as required in any prior version is also a breaking change.&lt;br /&gt;
Changing the IsRequired property value from true to false is not breaking, but changing it from false to true may be breaking if any prior versions of the type do not have the data member in question.&lt;br /&gt;
&lt;b&gt;Note&lt;/b&gt;: Although the IsRequired property is set to true, the incoming data may be null or zero, and a type must be prepared to handle this possibility. Do not use IsRequired as a security mechanism to protect against bad incoming data.&lt;br /&gt;
&lt;h2&gt;
&lt;span class=&quot;mw-headline&quot; id=&quot;Best_Practice_Usage_and_Guidelines&quot;&gt;Best Practice Usage and Guidelines&lt;/span&gt;&lt;/h2&gt;
&lt;h3&gt;
&lt;span class=&quot;mw-headline&quot; id=&quot;Best_Practice_Usage_-Operation_Change_and_Versioning&quot;&gt;Best Practice Usage -Operation Change and Versioning&lt;/span&gt;&lt;/h3&gt;
If you are adding a new operation, simply define a new service contract that derives from the service contract of the existing service, add the new operations to the new service contract, and then have your service type, the class that implements the existing service contract, implement the new service contract instead of the old one. Update the definition of the service endpoint so that it refers to the new, derived service contract. Now existing clients, which will only know about the old service contract, can have the operations that they already knew executed at the original endpoint, and new clients, which know about the enhanced service contract, can have the additional operations executed at the same endpoint. &lt;br /&gt;[ServiceContract] &lt;br /&gt;
&lt;pre&gt;public interface IMyServiceContract 
{    
[OperationContract]    
 public void MyMethod(MyDataContract input); 
} 
 
[ServiceContract] 
public interface IMyAugmentedServiceContract: IMyServiceContract 
{    
 [OperationContract]    
 public void MyNewMethod(MyOtherDataContract input); 
}   
 
public class MyOriginalServiceType: IAugmentedServiceContract
If you are deleting an operation or changing a data contract type
&lt;/pre&gt;
&lt;h3&gt;
&lt;span class=&quot;mw-headline&quot; id=&quot;Best_Practice_Usage-Data_Contract_Changes_and_Versioning&quot;&gt;Best Practice Usage-Data Contract Changes and Versioning&lt;/span&gt;&lt;/h3&gt;
&lt;h4&gt;
&lt;span class=&quot;mw-headline&quot; id=&quot;Breaking_versus_Nonbreaking_Changes&quot;&gt;Breaking versus Nonbreaking Changes&lt;/span&gt;&lt;/h4&gt;
Changes to a data contract can be breaking or nonbreaking. When a data contract is changed in a nonbreaking way, an application using the older version of the contract can communicate with an application using the newer version, and an application using the newer version of the contract can communicate with an application using the older version. On the other hand, a breaking change prevents communication in one or both directions. &lt;br /&gt;
Any changes to a type that do not affect how it is transmitted and received are nonbreaking. Such changes do not change the data contract, only the underlying type. For example, you can change the name of a field in a nonbreaking way if you then set the &lt;a class=&quot;external text&quot; href=&quot;http://msdn.microsoft.com/en-us/library/system.runtime.serialization.datamemberattribute.name.aspx&quot; rel=&quot;nofollow&quot;&gt;Name&lt;/a&gt; property of the &lt;a class=&quot;external text&quot; href=&quot;http://msdn.microsoft.com/en-us/library/system.runtime.serialization.datamemberattribute.aspx&quot; rel=&quot;nofollow&quot;&gt;DataMemberAttribute&lt;/a&gt; to the older version name. The following code shows version 1 of a data contract.&lt;br /&gt;
&lt;pre&gt;  
// Version 1
[DataContract]
public class Person
{
    [DataMember]
    private string Phone;
}
&lt;/pre&gt;
&lt;br /&gt;&lt;br /&gt;The following code shows a nonbreaking change.&lt;br /&gt;
&lt;pre&gt; 
// Version 2. This is a non-breaking change because the data contract 
// has not changed, even though the type has.
[DataContract]
public class Person
{
    [DataMember(Name = &quot;Phone&quot;)]
    private string Telephone;
}
&lt;/pre&gt;
Some changes do modify the transmitted data, but may or may not be breaking. The following changes are always breaking:&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;Changing the Name or Namespace value of a data contract.&lt;/li&gt;
&lt;li&gt;Changing the order of data members by using the Order property of the DataMemberAttribute.&lt;/li&gt;
&lt;li&gt;Renaming a data member.&lt;/li&gt;
&lt;li&gt;Changing the data contract of a data member. For example, changing the type of data member from an integer to a string, or from a type with a data contract named &quot;Customer&quot; to a type with a data contract named &quot;Person&quot;.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
&lt;span class=&quot;mw-headline&quot; id=&quot;Schema_Considerations&quot;&gt;Schema Considerations&lt;/span&gt;&lt;/h3&gt;
The schema WCF produces for data contract types makes no provisions for versioning. That is, the schema exported from a certain version of a type contains only those data members present in that version. Implementing the &lt;a class=&quot;external text&quot; href=&quot;http://msdn.microsoft.com/en-us/library/system.runtime.serialization.iextensibledataobject.aspx&quot; rel=&quot;nofollow&quot;&gt;IExtensibleDataObject&lt;/a&gt; interface does not change the schema for a type.&lt;br /&gt;
Data members are exported to the schema as optional elements by default. That is, the minOccurs (XML attribute) value is set to zero. Required data members are exported with minOccurs set to 1.&lt;br /&gt;
Many of the changes considered to be nonbreaking are actually breaking if strict adherence to the schema is required. In the preceding example, a CarV1 instance with just the Model element would validate against the CarV2 schema (which has both Model and Horsepower, but both are optional). However, the reverse is not true: a CarV2 instance would fail validation against the CarV1 schema.&lt;br /&gt;
Round-tripping also entails some additional considerations. For more information, see the &quot;Schema Considerations&quot; section in &lt;a class=&quot;external text&quot; href=&quot;http://msdn.microsoft.com/en-us/library/ms731083.aspx&quot; rel=&quot;nofollow&quot;&gt;Forward-Compatible Data Contracts&lt;/a&gt;.&lt;br /&gt;
&lt;h3&gt;
&lt;span class=&quot;mw-headline&quot; id=&quot;Guidelines&quot;&gt;Guidelines&lt;/span&gt;&lt;/h3&gt;
&lt;h4&gt;
&lt;span class=&quot;mw-headline&quot; id=&quot;Enumerations&quot;&gt;Enumerations&lt;/span&gt;&lt;/h4&gt;
Adding or removing an enumeration member is a breaking change. Changing the name of an enumeration member is breaking, unless its contract name is kept the same as in the old version by using the EnumMemberAtttribute attribute. For more information, see &lt;a class=&quot;external text&quot; href=&quot;http://msdn.microsoft.com/en-us/library/aa347875.aspx&quot; rel=&quot;nofollow&quot;&gt;Enumeration Types&lt;/a&gt; in Data Contracts.&lt;br /&gt;
&lt;h4&gt;
&lt;span class=&quot;mw-headline&quot; id=&quot;Collections&quot;&gt;Collections &lt;/span&gt;&lt;/h4&gt;
Most collection changes are nonbreaking because most collection types are interchangeable with each other in the data contract model. However, making a noncustomized collection customized or vice versa is a breaking change. Also, changing the collection&#39;s customization settings is a breaking change; that is, changing its data contract name and namespace, repeating element name, key element name, and value element name. For more information about collection customization, see &lt;a class=&quot;external text&quot; href=&quot;http://msdn.microsoft.com/en-us/library/aa347850.aspx&quot; rel=&quot;nofollow&quot;&gt;Collection Types in Data Contracts&lt;/a&gt;.&lt;br /&gt;
&lt;h3&gt;
&lt;span class=&quot;mw-headline&quot; id=&quot;Other_Permitted_Changes&quot;&gt;Other Permitted Changes &lt;/span&gt;&lt;/h3&gt;
Implementing the IExtensibleDataObject interface is a nonbreaking change. However, round-tripping support does not exist for versions of the type prior to the version in which IExtensibleDataObject was implemented. For more information, see &lt;a class=&quot;external text&quot; href=&quot;http://msdn.microsoft.com/en-us/library/ms731083.aspx&quot; rel=&quot;nofollow&quot;&gt;Forward-Compatible Data Contracts&lt;/a&gt;.&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://technicalwizardry.blogspot.com/feeds/9687380775135875/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4930197226974329220/9687380775135875' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4930197226974329220/posts/default/9687380775135875'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4930197226974329220/posts/default/9687380775135875'/><link rel='alternate' type='text/html' href='http://technicalwizardry.blogspot.com/2013/04/how-to-do-versioning-in-wcf.html' title='How to do Versioning in WCF'/><author><name>lloyd</name><uri>http://www.blogger.com/profile/04794204354889644869</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgA5q0xlK7umtyyBWFkMQwZQOonP5LuVNL3QnnfiZ409SLryDamMSxGdyRR_LciyL1hZR4-DjkZSY7MmTEMdAChFXno-bc9lW3Lo5xV3dYQvdK11xedJ3oJG1_C6fxBgXE/s220/IMG_0236.jpg'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhzijTXCjIyr36_6Rh-_0kTNYwKWg8KxxCJSPCpwjrl1OVakf1DgON_vdYq3QNwSvvUiRBYiftqaT7Id6uv5-wmS6ZYEoPBiAnSLbaJxTPEj-K8ugITM5UqnFL9hphLz1fpLi_8J6DN0og/s72-c/Versioning_Decision_Tree.jpg" height="72" width="72"/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4930197226974329220.post-6571162366897676555</id><published>2013-04-02T23:30:00.001-07:00</published><updated>2013-04-03T00:29:14.362-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="aspnet mvc"/><category scheme="http://www.blogger.com/atom/ns#" term="C#"/><category scheme="http://www.blogger.com/atom/ns#" term="mvc"/><category scheme="http://www.blogger.com/atom/ns#" term="technical"/><title type='text'>ASP.NET MVC Best practise</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none; text-align: left;&quot; trbidi=&quot;on&quot;&gt;
This page provides guidance and best practices on ASP.NET Model View Controller (MVC), which is a framework for building web application. The page also discusses on ASP.NET MVC advantages, features and how to use the framework to build a web application.&lt;br /&gt;
&lt;h2 style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;
&lt;span class=&quot;mw-headline&quot; id=&quot;What_is_ASP.NET_MVC.3F&quot;&gt;What is ASP.NET MVC?&lt;/span&gt;&lt;/h2&gt;
&lt;div style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;
ASP.NET MVC is a part of the ASP.NET Web application framework.&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none; clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhQaBAIewJD1B18SrQQN_UzjJAH8EgKUUzyhrBAn_FFTaFX9ZKtFL7G4xibvufKSbGm5TnUI2PaO1pp6Z3lqGZcSCz4MXy8NUQadECvJtDvRIhdQYh1AkHn5oF8jF-FUjSW2GbUZ2vTlBc/s1600/ASP_NET_frameworks.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; mta=&quot;true&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhQaBAIewJD1B18SrQQN_UzjJAH8EgKUUzyhrBAn_FFTaFX9ZKtFL7G4xibvufKSbGm5TnUI2PaO1pp6Z3lqGZcSCz4MXy8NUQadECvJtDvRIhdQYh1AkHn5oF8jF-FUjSW2GbUZ2vTlBc/s1600/ASP_NET_frameworks.jpg&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;
ASP.NET MVC framework was created to support pattern-based software development. In other words, the framework was designed to make it easier to implement software design principles and patterns when building web applications. It is designed to its core to support unit tests. Web applications written with the ASP.NET MVC framework are highly testable.&lt;/div&gt;
&lt;h2 style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;
&lt;span class=&quot;mw-headline&quot; id=&quot;Why_ASP.NET_MVC.3F&quot;&gt;Why ASP.NET MVC?&lt;/span&gt;&lt;/h2&gt;
&lt;div style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;
ASP.NET Web Forms made it very easy to get started, but, in other ways, trying to apply design principles to Web apps was a struggle. Web Forms are relentlessly UI focused; the fundamental atom is the page. The page is designed by dragging controls in to it. And the application logic that we have usually will reside in event handlers. Unit testing of pages is often difficult. ASP.NET MVC is a solution addressing these issues.&lt;/div&gt;
The ASP.NET MVC framework provides the following features:&lt;br /&gt;
&lt;ul&gt;
&lt;li style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;Separation of application tasks (input logic, business logic, and UI logic), testability, and test-driven development (TDD) by default. All core contracts in the MVC framework are interface-based and can be tested by using mock objects, which are simulated objects that imitate the behavior of actual objects in the application. We can unit-test the application without having to run the controllers in an ASP.NET process, which makes unit testing fast and flexible. We can use any unit-testing framework that is compatible with the .NET Framework. &lt;/li&gt;
&lt;li style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;An extensible and pluggable framework. The components of the ASP.NET MVC framework are designed so that they can be easily replaced or customized. We can plug in our own view engine, URL routing policy, action-method parameter serialization, and other components. The ASP.NET MVC framework also supports the use of Dependency Injection (DI) and Inversion of Control (IOC) container models. DI allows us to inject objects into a class, instead of relying on the class to create the object itself. IOC specifies that if an object requires another object, the first objects should get the second object from an outside source such as a configuration file. This makes testing easier. &lt;/li&gt;
&lt;li style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;A powerful URL-mapping component that lets us build applications that have comprehensible and searchable URLs. URLs do not have to include file-name extensions, and are designed to support URL naming patterns that work well for search engine optimization (SEO) and representational state transfer (REST) addressing. &lt;/li&gt;
&lt;li style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;Support for using the markup in existing ASP.NET page (.aspx files), user control (.ascx files), and master page (.master files) markup files as view templates. We can use existing ASP.NET features with the ASP.NET MVC framework, such as nested master pages, in-line expressions (&amp;lt;%=&amp;nbsp;%&amp;gt;), declarative server controls, templates, data-binding, localization, and so on. &lt;/li&gt;
&lt;li&gt;Support for existing ASP.NET features. ASP.NET MVC lets us use features such as forms authentication and Windows authentication, URL authorization, membership and roles, output and data caching, session and profile state management, health monitoring, the configuration system, and the provider architecture.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;
&lt;span class=&quot;mw-headline&quot; id=&quot;ASP.NET_MVC_Framework_Overview&quot;&gt;ASP.NET MVC Framework Overview&lt;/span&gt;&lt;/h2&gt;
This framework is based around the Model View Controller (MVC) pattern, thus the name, ASP.NET MVC. An MVC Application is designed and implemented using the following three attributes:&lt;br /&gt;
&lt;div style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;
&lt;b&gt;Model&lt;/b&gt; - The model contains the core information for an application. This includes the data and validation rules as well as data access and aggregation logic. &lt;/div&gt;
&lt;div style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;
&lt;b&gt;View&lt;/b&gt; - The view encapsulates the presentation of the application, and in ASP.NET this is typically the HTML markup. &lt;/div&gt;
&lt;div style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;
&lt;b&gt;Controller&lt;/b&gt; - The controller contains the control-flow logic. It interacts with the Model and Views to control the flow of information and execution of the application.&lt;/div&gt;
&lt;div class=&quot;thumb tnone&quot; style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;
&lt;div class=&quot;thumbinner&quot; style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none; width: 336px;&quot;&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none; clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgrgD0KFdMuw4HcLTSpI9tI7nqap8zRRV6tLf0MBkz4UbcSOCwAxmphefsZaIBMV8Po4PkJVDdKBKv_CbmvEbJCYDSsCtjio4EUBP1FXnCTEGE5y-CQWGb0aO3Q6OxLHx-EwqOF_a055c8/s1600/Model-View-Controller_concept.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;225&quot; mta=&quot;true&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgrgD0KFdMuw4HcLTSpI9tI7nqap8zRRV6tLf0MBkz4UbcSOCwAxmphefsZaIBMV8Po4PkJVDdKBKv_CbmvEbJCYDSsCtjio4EUBP1FXnCTEGE5y-CQWGb0aO3Q6OxLHx-EwqOF_a055c8/s320/Model-View-Controller_concept.jpg&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;thumbcaption&quot;&gt;
&lt;div style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;
Fig 2 Model-View-Controller concept&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;
In the context of Web, the input is an HTTP request, and the request flow looks as shown below.&lt;/div&gt;
&lt;div style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none; clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEimS2_KYzINtj4OMBio0wIi57TB_KPFAStXerc2h66_epsPw9DyIVOo9mHRC5l4UWZnRvvec86uCRVGddNayV2o_6K7uf4QkXDUDVX7CAYFMMxAkjwz6xjo8nimc10p8EX46ac2oEjdvDI/s1600/HTTP_request_flow.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;320&quot; mta=&quot;true&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEimS2_KYzINtj4OMBio0wIi57TB_KPFAStXerc2h66_epsPw9DyIVOo9mHRC5l4UWZnRvvec86uCRVGddNayV2o_6K7uf4QkXDUDVX7CAYFMMxAkjwz6xjo8nimc10p8EX46ac2oEjdvDI/s320/HTTP_request_flow.jpg&quot; width=&quot;255&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;thumb tnone&quot; style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;
&lt;div class=&quot;thumbinner&quot; style=&quot;width: 266px;&quot;&gt;
&lt;div style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;thumbcaption&quot;&gt;
&lt;div style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;
Fig 3 HTTP request flow&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;
This is actually quite different from the process in Web Forms. In Web Forms model, the input goes into the page (the View), and the view is responsible for both handling the input and generating the output. When it comes to MVC, on the other hand, the responsibilities are separated.&lt;/div&gt;
&lt;h2 style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;
&lt;span class=&quot;mw-headline&quot; id=&quot;Features&quot;&gt;Features&lt;/span&gt;&lt;/h2&gt;
&lt;h3 style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;
&lt;span class=&quot;mw-headline&quot; id=&quot;System_Requirements&quot;&gt;System Requirements&lt;/span&gt;&lt;/h3&gt;
&lt;div style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;
The following is the system requirement for building ASP.NET MVC application.&lt;/div&gt;
&lt;ul&gt;
&lt;li style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;Visual Studio 2010/2008 or Visual Web Developer 2008 SP1/2010&lt;/li&gt;
&lt;li style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;NET Framework 3.5 SP1 or .NET Framework 4 &lt;/li&gt;
&lt;li style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;ASP.NET MVC 1/ASP.NET MVC 2&lt;/li&gt;
&lt;li style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;IIS 7.0 - integrated mode (For IIS 7.0 (classic mode), IIS 6.0 or below, configuration needs to be done to use ASP.NET routing)&lt;/li&gt;
&lt;li&gt;Visual Studio 2008 SP1 (in case of Visual Studio 2008)&lt;/li&gt;
&lt;/ul&gt;
&lt;h1 style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;
&lt;span class=&quot;mw-headline&quot; id=&quot;Process_Flow_in_ASP.NET-_Creating_a_Sample_ASP.NET_MVC_application&quot;&gt;Process Flow in ASP.NET- Creating a Sample ASP.NET MVC application&lt;/span&gt;&lt;/h1&gt;
Let us create an application to maintain team member information. The information that it maintains are as follows&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;First Name&lt;/li&gt;
&lt;li&gt;Last Name &lt;/li&gt;
&lt;li&gt;Employee Number&lt;/li&gt;
&lt;li style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;Login Id&lt;/li&gt;
&lt;li&gt;Date of Joining&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
&lt;span class=&quot;mw-headline&quot; id=&quot;Creating_a_ASP.NET_MVC_project_in_visual_studio&quot;&gt;Creating a ASP.NET MVC project in visual studio&lt;/span&gt;&lt;/h2&gt;
Follow the steps to create the application:&lt;br /&gt;
1. Launch Visual Studio&lt;br /&gt;
&lt;div style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;
2. Select the menu option File -&amp;gt; New -&amp;gt; Project. &lt;b&gt;Note&lt;/b&gt;: As of now there is no template available for creating ASP.NET MVC website&lt;/div&gt;
&lt;div style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;
3. In the New Project dialog, select programming language (C# or VB.NET) and select the ASP.NET MVC 2 Web Application template. Give the project name “TeamMemberInfoManager” and click OK. &lt;/div&gt;
&lt;div style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;
4. A Dialog asking for creating unit test project appears. Lets not create a test project for this application, so select No and click OK. &lt;/div&gt;
5. The solution gets created as shown as follows.&lt;br /&gt;
&lt;div class=&quot;thumb tnone&quot; style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj0wry-z68LojLDUFOHk6W-OjA2BgPh50RUZiNaP4NZEg_xMv6CzcZtz2Ma3kVCTYPnIithBCavAPlEN1g6E-Oc5gQJFT5F82ig94IukTkampx1DppX9DNF4LKs4y5CPkb3b5cVhHRu_G4/s1600/Solution_Explorer_-_Solution_&#39;TeamMemberInfoManager&#39;.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;320&quot; mta=&quot;true&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj0wry-z68LojLDUFOHk6W-OjA2BgPh50RUZiNaP4NZEg_xMv6CzcZtz2Ma3kVCTYPnIithBCavAPlEN1g6E-Oc5gQJFT5F82ig94IukTkampx1DppX9DNF4LKs4y5CPkb3b5cVhHRu_G4/s320/Solution_Explorer_-_Solution_&#39;TeamMemberInfoManager&#39;.jpg&quot; width=&quot;314&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;h3 style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;
&lt;span class=&quot;mw-headline&quot; id=&quot;ASP.NET_MVC_Folder_Convention&quot;&gt;ASP.NET MVC Folder Convention&lt;/span&gt;&lt;/h3&gt;
There are standard locations for each type of file in an ASP.NET MVC project. The ASP.NET MVC application project contains the following folders:&lt;br /&gt;
&lt;table class=&quot;wikitable&quot; style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;b&gt;Folder&lt;/b&gt;&lt;/td&gt;&lt;td&gt;&lt;b&gt;Description of the content&lt;/b&gt;&lt;/td&gt;&lt;td&gt;&lt;br /&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;App_Data &lt;/td&gt;&lt;td&gt;&lt;div style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;
Contains database files. For example, the App_Data folder might contain a local instance of a SQL Server Express database. This folder is not specific to ASP.NET MVC, this is same folder that we find in ASP.NET web application.&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Content&lt;/td&gt;&lt;td&gt;Contains static content such as images and Cascading Style Sheet files.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Controllers&lt;/td&gt;&lt;td&gt;Contains ASP.NET MVC controller classes&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Models&lt;/td&gt;&lt;td&gt;Contains ASP.NET MVC model classes.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Scripts&lt;/td&gt;&lt;td style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;Contains JavaScript files including the ASP.NET AJAX Library and jQuery&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Views&lt;/td&gt;&lt;td style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;&lt;div style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;
Contains ASP.NET MVC views.&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;div style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;
When building an ASP.NET MVC application, one should only place controllers in the Controllers folder, JavaScript scripts in the Scripts folder, ASP.NET MVC views in the Views folder, and so on. By following these conventions, we make our application more easily maintained and easily understood by others.&lt;/div&gt;
1. Run the solution created. The page looks as below.&lt;br /&gt;
&lt;div class=&quot;thumb tnone&quot; style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;
&lt;a class=&quot;image&quot; href=&quot;http://www.blogger.com/tgtwiki/index.php/File:HTTP_request_flow.JPG&quot; style=&quot;clear: right; cssfloat: right; float: right; margin-bottom: 1em; margin-left: 1em;&quot;&gt;&lt;/a&gt;&lt;a class=&quot;image&quot; href=&quot;http://www.blogger.com/tgtwiki/index.php/File:Model-View-Controller_concept.JPG&quot; style=&quot;clear: right; cssfloat: right; float: right; margin-bottom: 1em; margin-left: 1em;&quot;&gt;&lt;/a&gt;&lt;br /&gt;
&lt;div class=&quot;thumbinner&quot; style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none; width: 442px;&quot;&gt;
&lt;div style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none; clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgR1ADfwwd7nGFyughvqbv297uRTOJB__RbLgszRwGaO24DYHcAG8kNVIT-9jgRl_VNvHzW7mNNDjWaKb0DlIiCgDiZTvtiuFWxCDgnP5uSgTgTfEHb1xQSSu71gW9n6OMuDJRzB4ARjYE/s1600/ASP__Net_MVC_Home_Page.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;207&quot; mta=&quot;true&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgR1ADfwwd7nGFyughvqbv297uRTOJB__RbLgszRwGaO24DYHcAG8kNVIT-9jgRl_VNvHzW7mNNDjWaKb0DlIiCgDiZTvtiuFWxCDgnP5uSgTgTfEHb1xQSSu71gW9n6OMuDJRzB4ARjYE/s320/ASP__Net_MVC_Home_Page.jpg&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;thumbcaption&quot;&gt;
&lt;div style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;
Fig 7 ASP .Net MVC Home Page&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;
Let us implement Create and Edit functionalities for team members.&lt;/div&gt;
&lt;h3 style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;
&lt;span class=&quot;mw-headline&quot; id=&quot;Model&quot;&gt;Model&lt;/span&gt;&lt;/h3&gt;
&lt;div style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;
The model contains the core information for an application. This includes the data and validation rules as well as data access and aggregation logic.&lt;/div&gt;
&lt;div style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;
1. Right click on “Models” folder and add new class “TeamMemberModels”.&lt;/div&gt;
&lt;div class=&quot;thumb tnone&quot; style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;
&lt;div class=&quot;thumbinner&quot; style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none; width: 484px;&quot;&gt;
&lt;div style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;thumbcaption&quot;&gt;
&lt;div style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none; clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhA6atSMJdokuS69RAOSq7ZPXJPFP3UGVtMdElyT8YOeUZdEAkD0fpU248tP6at7tWqazSNYpU7q-gAcR90RH-308kY5r3eserA4JaSn0JxKuqDBb7uI3L4poNkZpIv2kNtG9tam4wYBVo/s1600/Add_New_Item.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;198&quot; mta=&quot;true&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhA6atSMJdokuS69RAOSq7ZPXJPFP3UGVtMdElyT8YOeUZdEAkD0fpU248tP6at7tWqazSNYpU7q-gAcR90RH-308kY5r3eserA4JaSn0JxKuqDBb7uI3L4poNkZpIv2kNtG9tam4wYBVo/s320/Add_New_Item.jpg&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;
Fig 8 Add New Item&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;
2. Change the code in the file to look as below.&lt;/div&gt;
&lt;pre style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
 
namespace TeamMemberInfoManager.Models
{
    public class TeamMember
    {
        public String FirstName { get; set; }
        public String LastName { get; set; }
        public String EmployeeNumber { get; set; }
        public String LoginId { get; set; }
        public DateTime DateOfJoining { get; set; }
    }
}
&lt;/pre&gt;
3. Let us implement the logic for creating and maintaining team members. IRepository is an interface defining the behavior of create and update. The code for IRepository looks as follows. Create this interface within folder Models.&lt;br /&gt;
&lt;pre&gt;using TeamMemberInfoManager.Models;
using System.Collections.Generic;
interface IRepository
{
    void Add(TeamMember newTeamMember);
    TeamMember Search(string EmployeeNumber);
    List&amp;lt;TeamMember&amp;gt; getAllTeamMembers();
    void Update(TeamMember updatedTeamMember, string    employeeNumber);
}
&lt;/pre&gt;
4. Let us implement Repository as below in the folder Models. This has the code implementing the behavior&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;&lt;ol&gt;
&lt;li&gt;Add new team member&lt;/li&gt;
&lt;li&gt;Search for a team member&lt;/li&gt;
&lt;li&gt;Get all team members&lt;/li&gt;
&lt;li&gt;Update a team member info&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;pre style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
 
namespace TeamMemberInfoManager.Models
{
    public class Repository&amp;nbsp;: IRepository
    {
        static List&amp;lt;TeamMember&amp;gt; teamMembers = new List&amp;lt;TeamMember&amp;gt;();
 
        public void Add(TeamMember newTeamMember)
        {
            teamMembers.Add(newTeamMember);
        }
 
        public TeamMember Search(string employeeNumber)
        {
            foreach (TeamMember member in teamMembers)
            {
                if (string.Compare(member.EmployeeNumber, employeeNumber, true) == 0)
                {
                    return member;
                }
            }
            return null;
        }
        public List&amp;lt;TeamMember&amp;gt; getAllTeamMembers() 
        { 
                return teamMembers;
        }
        public void Update(TeamMember updatedTeamMember, string employeeNumber)
        {
            teamMembers.Remove(Search(employeeNumber));
            teamMembers.Add(updatedTeamMember);
        }
    }
}
&lt;/pre&gt;
&lt;h3&gt;
&lt;span class=&quot;mw-headline&quot; id=&quot;Controller&quot;&gt;Controller&lt;/span&gt;&lt;/h3&gt;
&lt;div style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;
The ASP.NET MVC framework maps URLs to classes that are referred to as controllers. Controllers process incoming requests, handle user input and interactions, and execute appropriate application logic. A controller class typically calls a separate view component to generate the HTML markup for the request.&lt;/div&gt;
&lt;div style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;
1. Right click on Controllers folder, Add Controller…&lt;/div&gt;
&lt;div class=&quot;thumb tnone&quot; style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;
&lt;div class=&quot;thumbinner&quot; style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none; width: 297px;&quot;&gt;
&lt;div style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;thumbcaption&quot;&gt;
&lt;div style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjzvId6Kf9EjpuBfVWLWdTBDDUgvjQRlIQRn5pT4JaWJjWlR4Eg28eZ1abgYI7k9nRoF3GJBGrB9vTpusYnNSB5fb4OAT_7bxBLGd-k55M3JeseG3PTa5nFH8NC202aAbwNAQ7wEvPvFr0/s1600/Controllers_folder.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;320&quot; mta=&quot;true&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjzvId6Kf9EjpuBfVWLWdTBDDUgvjQRlIQRn5pT4JaWJjWlR4Eg28eZ1abgYI7k9nRoF3GJBGrB9vTpusYnNSB5fb4OAT_7bxBLGd-k55M3JeseG3PTa5nFH8NC202aAbwNAQ7wEvPvFr0/s320/Controllers_folder.jpg&quot; width=&quot;258&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;
Fig 9 Controllers folder&lt;/div&gt;
&lt;div style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
2. Give the name as “TeamMemberController”. Controller files should always be suffixed with the word “Controller”. Select the check box to create action methods for create, update and detail.&lt;br /&gt;
3. Code gets generated for Create, Update and Details.&lt;br /&gt;
&lt;div style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;
The base class for all controllers is the ControllerBase class, which provides general MVC handling. The Controller class inherits from ControllerBase. The Controller class is responsible for the following processing stages:&lt;/div&gt;
&lt;ol&gt;
&lt;li&gt;Locating the appropriate action method to call and validating that it can be called.&lt;/li&gt;
&lt;li&gt;Getting the values to use as the action method&#39;s arguments.&lt;/li&gt;
&lt;li&gt;Handling all errors that might occur during the execution of the action method.&lt;/li&gt;
&lt;li style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;Providing the default WebFormViewEngine class for rendering ASP.NET page types (views).&lt;/li&gt;
&lt;/ol&gt;
The methods in the controller are the actions exposed by the controller. The URL /TeamMember/Index invokes TeamMember.Index() method and the URL /TeamMember/Create invokes TeamMember.Create () method.&lt;br /&gt;
A controller action returns action result. The ASP.NET MVC framework supports several types of action results including:&lt;br /&gt;
&lt;ul&gt;
&lt;li style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;ViewResult - Represents HTML and markup. &lt;/li&gt;
&lt;li style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;EmptyResult - Represents no result. &lt;/li&gt;
&lt;li&gt;RedirectResult - Represents a redirection to a new URL. &lt;/li&gt;
&lt;li&gt;JsonResult - Represents a JavaScript Object Notation result that can be used in an AJAX application. &lt;/li&gt;
&lt;li&gt;JavaScriptResult - Represents a JavaScript script. &lt;/li&gt;
&lt;li&gt;ContentResult - Represents a text result. &lt;/li&gt;
&lt;li&gt;FileContentResult - Represents a downloadable file (with the binary content). &lt;/li&gt;
&lt;li&gt;FilePathResult - Represents a downloadable file (with a path). &lt;/li&gt;
&lt;li&gt;FileStreamResult - Represents a downloadable file (with a file stream). &lt;/li&gt;
&lt;/ul&gt;
All of these action results inherit from the base ActionResult class.&lt;br /&gt;
The controller action Index exposed by TeamMemberController return a function View() which returns a ViewResult. A view contains the HTML markup and content that is sent to the browser. A view is the equivalent of a page when working with an ASP.NET MVC application.&lt;br /&gt;
In order to be exposed to the universe as an action, a method in a controller must meet below requirements:&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;The method must be public. &lt;/li&gt;
&lt;li&gt;The method cannot be a static method. &lt;/li&gt;
&lt;li&gt;The method cannot be an extension method. &lt;/li&gt;
&lt;li&gt;The method cannot be a constructor, getter, or setter. &lt;/li&gt;
&lt;li&gt;The method cannot have open generic types. &lt;/li&gt;
&lt;li&gt;The method is not a method of the controller base class. &lt;/li&gt;
&lt;li&gt;The method cannot contain ref or out parameters. &lt;/li&gt;
&lt;/ul&gt;
If we need a public method in a controller class which should not be exposed as an action, use the attribute [NoAction]. In the example below, the method CompanySecrets is not exposed to public as an action.&lt;br /&gt;
&lt;pre&gt;namespace MvcApplication1.Controllers
{
    public class WorkController&amp;nbsp;: Controller
    {
        [NonAction]
        public string CompanySecrets()
        {
            return &quot;This information is secret.&quot;;
        }
 
    }
}
&lt;/pre&gt;
Let us update the methods generated in control to make it work.&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;Implement Index method to return all team members, to display on initial page.&lt;/li&gt;
&lt;li&gt;Remove Details method, as we are not implementing this functionality.&lt;/li&gt;
&lt;li&gt;Update HTTPPost, Create method to add new team member to the list.&lt;/li&gt;
&lt;li&gt;Update Edit method to return a particular team member which needs to be edited.&lt;/li&gt;
&lt;li&gt;Update HttpPost, Edit method to update a team member information.&lt;/li&gt;
&lt;/ul&gt;
The code looks as below after the change.&lt;br /&gt;
&lt;pre&gt;using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using TeamMemberInfoManager.Models;
namespace TeamMemberInfoManager.Controllers
{    
    public class TeamMemberController&amp;nbsp;: Controller
    {
        IRepository repo = new Repository();  
        // GET: /TeamMember/
        public ActionResult Index()
        {
            return View(repo.getAllTeamMembers());
        }     
        // GET: /TeamMember/Create       
        public ActionResult Create()
        {
            return View();
        } 
        // POST: /TeamMember/Create
        [HttpPost]
        public ActionResult Create(TeamMember newTeamMember)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    repo.Add(newTeamMember);
                    return View(&quot;Index&quot;, repo.getAllTeamMembers());                    
                }
                else
                {
                    return View();
                }                
            }
            catch
            {
                return View();
            }
        }
        // GET: /TeamMember/Edit/5 
        public ActionResult Edit(String id)
        {
            return View(repo.Search(id));            
        }
        // POST: /TeamMember/Edit/5
        [HttpPost]
        public ActionResult Edit(String id, TeamMember updatedTeamMember)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    repo.Update(updatedTeamMember, id);
                    return View(&quot;Index&quot;, repo.getAllTeamMembers());                   
                }
                else
                {
                    return View();
                }                
             }
            catch
            {
                return View();
            }
        }
    }
}
&lt;/pre&gt;
&lt;h2&gt;
&lt;span class=&quot;mw-headline&quot; id=&quot;View&quot;&gt;View&lt;/span&gt;&lt;/h2&gt;
The view encapsulates the presentation of the application, and this is typically the HTML markup. The folder includes .aspx pages. The views must be created at right location. The TeamMemberController.Index() action returns a view located at the path “\Views\TeamMember\Index.aspx”. The TeamMemberController.Create() action returns a view located at the path “\Views\ TeamMember\Create.aspx”&lt;br /&gt;
In general, the controller action returns a view that is located at subfolder with same name as that of controller within the folder “Views” and with the same name as that of action.&lt;br /&gt;
&lt;h3&gt;
&lt;span class=&quot;mw-headline&quot; id=&quot;Creating_a_view_for_action_.E2.80.9CIndex.E2.80.9D&quot;&gt;Creating a view for action “Index”&lt;/span&gt;&lt;/h3&gt;
&lt;div style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;
To create a view for action index, perform the following:&lt;/div&gt;
1. Right click on the method and “Add View”. This creates the page and the corresponding folder if doesn’t exists.&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none; clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;thumb tnone&quot; style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;
&lt;div class=&quot;thumbinner&quot; style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none; width: 371px;&quot;&gt;
&lt;div style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;thumbcaption&quot; style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;
&lt;div style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjUhzvQMiy53gZWaxKRSZOFRMe1tZWp8Zv4wDgSQlK4JP-qjE_tmCvJvTkyJkfKbKWaBWnw_OlaGafLyq5ZB8QFT53DEuKnes7Q8zCDx32DH-wjPtKhgtN6d57SuGwm8k71VqbDgoAYOII/s1600/Action_index.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;215&quot; mta=&quot;true&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjUhzvQMiy53gZWaxKRSZOFRMe1tZWp8Zv4wDgSQlK4JP-qjE_tmCvJvTkyJkfKbKWaBWnw_OlaGafLyq5ZB8QFT53DEuKnes7Q8zCDx32DH-wjPtKhgtN6d57SuGwm8k71VqbDgoAYOII/s320/Action_index.jpg&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;
Fig 10 Action index&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;
2. There is an option to create “strongly-typed view”. Let us choose this and select the options as below. This means that index page should display a List of team members. (If you cannot see the TeamMember class in the dropdown, build the application and try again.)&lt;/div&gt;
&lt;div class=&quot;thumb tnone&quot; style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;
&lt;div class=&quot;thumbinner&quot; style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none; width: 333px;&quot;&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiDz8prqgjCRPt-JLhYUm7CHr3nlDgwwjVaKjLWFrXQqDfKO6iNvnhPkHgzaY8j8FlsWaFvT5mnftRGH6oQJYrX7W6cTgvGRUd_OlQ1MkavAXJGFipx57bZXFIorK4vw06mmXvqeohMxxo/s1600/Add_view_-_List.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;319&quot; mta=&quot;true&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiDz8prqgjCRPt-JLhYUm7CHr3nlDgwwjVaKjLWFrXQqDfKO6iNvnhPkHgzaY8j8FlsWaFvT5mnftRGH6oQJYrX7W6cTgvGRUd_OlQ1MkavAXJGFipx57bZXFIorK4vw06mmXvqeohMxxo/s320/Add_view_-_List.jpg&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;thumbcaption&quot;&gt;
Fig 11 Add view - List&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;
Un-checking both “Create a partial view (.ascx)” and “Create a strongly-typed view” will create a blank page.&lt;/div&gt;
&lt;div style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;
Choosing partial view creates a user control for the action.&lt;/div&gt;
&lt;div style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;
There are 2 ways how the data can be transferred from controller to view. &lt;/div&gt;
&lt;div style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;
&lt;b&gt;Loosely –typed dictionary&lt;/b&gt;&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;Uses ViewData dictionary to store string-object as a key-value pair. &lt;/li&gt;
&lt;li style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;Need to typecast the object, every time while using.&lt;/li&gt;
&lt;/ul&gt;
&lt;b&gt;Strongly –typed dictionary&lt;/b&gt;&lt;br /&gt;
&lt;ul&gt;
&lt;li style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;A particular type of object, specified as a model is expected by the view. &lt;/li&gt;
&lt;li style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;ViewDataDictionary&amp;lt;TModel&amp;gt; represents a container that is used to pass strongly typed data between a controller and a view.&lt;/li&gt;
&lt;li&gt;For strongly-typed view, view page inherits from ViewPage&amp;lt;T&amp;gt; class.&lt;/li&gt;
&lt;li&gt;The object passed to view is accessed through a variable named model.&lt;/li&gt;
&lt;/ul&gt;
A view created is a standard (X)HTML document that can contain scripts. The script is enclosed with the tags &amp;lt;% and&amp;nbsp;%&amp;gt;. &lt;br /&gt;
&lt;div style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;
Note: ASP.NET 4 is introducing new code expression syntax &amp;lt;%:&amp;nbsp;%&amp;gt; that renders output like &amp;lt;%=&amp;nbsp;%&amp;gt; block do and also does HTML encoding before rendering.&lt;/div&gt;
&lt;h3&gt;
&lt;span class=&quot;mw-headline&quot; id=&quot;HTML_Helpers&quot;&gt;HTML Helpers&lt;/span&gt;&lt;/h3&gt;
To make it easier to add content to a view, we can take advantage of something called an HTML Helper. An HTML Helper, typically, is a method that generates a string. We can use HTML Helpers to generate standard HTML elements such as textboxes, links, dropdown lists, and list boxes. The code looks as below.&lt;br /&gt;
&lt;pre&gt;&amp;lt;body&amp;gt;
    &amp;lt;div&amp;gt;    
    &amp;lt;% using (Html.BeginForm())
       {&amp;nbsp;%&amp;gt;   
        &amp;lt;label for=&quot;UserName&quot;&amp;gt;User Name:&amp;lt;/label&amp;gt;
        &amp;lt;br /&amp;gt;
        &amp;lt;%= Html.TextBox(&quot;UserName&quot;)&amp;nbsp;%&amp;gt;        
        &amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;            
        &amp;lt;label for=&quot;Password&quot;&amp;gt;Password:&amp;lt;/label&amp;gt;
        &amp;lt;br /&amp;gt;
        &amp;lt;%= Html.Password(&quot;Password&quot;)&amp;nbsp;%&amp;gt;        
        &amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;
        &amp;lt;input type=&quot;submit&quot; value=&quot;Log in&quot; /&amp;gt;            
    &amp;lt;% }&amp;nbsp;%&amp;gt;    
    &amp;lt;/div&amp;gt;
&amp;lt;/body&amp;gt;
&lt;/pre&gt;
HTML Helper is rendered with &amp;lt;%=&amp;nbsp;%&amp;gt; tags instead of &amp;lt;%&amp;nbsp;%&amp;gt; tags. If you don&#39;t include the equal sign, then nothing gets rendered to the browser.&lt;br /&gt;
Below are the few standard HTML Helpers available.&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;Html.ActionLink() &lt;/li&gt;
&lt;li&gt;Html.BeginForm() &lt;/li&gt;
&lt;li&gt;Html.CheckBox() &lt;/li&gt;
&lt;li&gt;Html.DropDownList() &lt;/li&gt;
&lt;li&gt;Html.EndForm() &lt;/li&gt;
&lt;li&gt;Html.Hidden() &lt;/li&gt;
&lt;li&gt;Html.ListBox() &lt;/li&gt;
&lt;li&gt;Html.Password() &lt;/li&gt;
&lt;li&gt;Html.RadioButton() &lt;/li&gt;
&lt;li&gt;Html.TextArea() &lt;/li&gt;
&lt;li&gt;Html.TextBox()&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
&lt;span class=&quot;mw-headline&quot; id=&quot;View_Data&quot;&gt;View Data&lt;/span&gt;&lt;/h3&gt;
View data is used to pass data from a controller to a view. All data passed from a controller to a view must be sent using this package view data. The controller ViewData property represents a collection of name and value pairs.&lt;br /&gt;
As we are done with creating Model, Controller and View for Index, let us run the application.&lt;br /&gt;
1. Run the application. Suffix the URL with “TeamMember/Index” and refresh the page. It looks as below. As there is no team member information, the grid is empty.&lt;br /&gt;
&lt;div class=&quot;thumb tnone&quot; style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;
&lt;div class=&quot;thumbinner&quot; style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none; width: 417px;&quot;&gt;
&lt;div style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;thumbcaption&quot;&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjgscUfbMwyBPeuatAJg3983nK6V6NfUQdiH4h_0AlRPfFSNIS-IFnF4i-zu_MfstNxbJO8Hg6GJ4EUil3RYolwYSMKm0QeAVHWNk0MQ3q4wzhZFoFClRVULk48MW_CwEislakRi6Nj5ek/s1600/Application_Run_wth_TeamMemberIndex_as_the_suffix.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;194&quot; mta=&quot;true&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjgscUfbMwyBPeuatAJg3983nK6V6NfUQdiH4h_0AlRPfFSNIS-IFnF4i-zu_MfstNxbJO8Hg6GJ4EUil3RYolwYSMKm0QeAVHWNk0MQ3q4wzhZFoFClRVULk48MW_CwEislakRi6Nj5ek/s320/Application_Run_wth_TeamMemberIndex_as_the_suffix.jpg&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
Fig 13 Application Run wth TeamMemberIndex as the suffix&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;h2&gt;
&lt;span class=&quot;mw-headline&quot; id=&quot;Routing&quot;&gt;Routing&lt;/span&gt;&lt;/h2&gt;
&lt;div style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;
The URL specified in the browser gets mapped to a controller action through routing. ASP.NET Routing is used by ASP.NET MVC framework to route incoming requests to controller actions. ASP.NET Routing uses a route table to handle incoming requests.&lt;/div&gt;
When we create a new ASP.NET MVC application, the application is already configured to use ASP.NET Routing. ASP.NET Routing is setup in two places.&lt;br /&gt;
&lt;div style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;
First, ASP.NET Routing is enabled in our application&#39;s Web configuration file (Web.config file). There are four sections in the configuration file that are relevant to routing: the system.web.httpModules section, the system.web.httpHandlers section, the system.webserver.modules section, and the system.webserver.handlers section. Be careful not to delete these sections because without these sections routing will no longer work.&lt;/div&gt;
Second, and more importantly, a route table is created in the application&#39;s Global.asax file. The Global.asax file is a special file that contains event handlers for ASP.NET application lifecycle events. The route table is created during the Application Start event. The code in the files is as follows&lt;br /&gt;
&lt;pre&gt;public class MvcApplication&amp;nbsp;: System.Web.HttpApplication
    {
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute(&quot;{resource}.axd/{*pathInfo}&quot;);
 
            routes.MapRoute(
                &quot;Default&quot;,                                              // Route name
                &quot;{controller}/{action}/{id}&quot;,                           // URL with parameters
                new { controller = &quot;Home&quot;, action = &quot;Index&quot;, id = &quot;&quot; }  // Parameter defaults
            );
 
        }
 
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
 
            RegisterRoutes(RouteTable.Routes);
        }
    }
&lt;/pre&gt;
The default route table contains a single route (named Default). The Default route maps the first segment of a URL to a controller name, the second segment of a URL to a controller action, and the third segment to a parameter named id. &lt;br /&gt;
Default route maps the URL “/Home/Index/3” to following parameters: &lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;controller = Home&lt;/li&gt;
&lt;li&gt;action = Index&lt;/li&gt;
&lt;li&gt;id = 3&lt;/li&gt;
&lt;/ul&gt;
When we request the URL /Home/Index/3, the code that gets executed is “HomeController.Index(3)”&lt;br /&gt;
The Default route includes defaults for all three parameters. If we don&#39;t supply a controller, then the controller parameter defaults to the value &lt;b&gt;Home&lt;/b&gt;. If we don&#39;t supply an action, the action parameter defaults to the value &lt;b&gt;Index&lt;/b&gt;. Finally, if we don&#39;t supply an id, the id parameter defaults to an empty string.&lt;br /&gt;
&lt;div style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;
As there is no data to display in Index page, let us create a view for create, so that the data created gets shown in page Index.&lt;/div&gt;
&lt;div style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;
1. Adding a view for Create. Right click on method Create and add the page by selecting the options as shown below.&lt;/div&gt;
&lt;div class=&quot;thumb tnone&quot; style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;
&lt;div class=&quot;thumbinner&quot; style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none; width: 281px;&quot;&gt;
&lt;div style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;thumbcaption&quot; style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;
&lt;div style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg1TE8flvkCIOUyWSuTWQWC1tfnJ3zQ2NqW6pKDFb5KO8I4MdpORqcBsBCmugKq2BJva8ZaAFwJfTDqp3DoXELrgAU5r1C1_VxAkTeLNqqQFDtcFgg6kEtNZGtVB89wAsYsCC_Ad_P2-k4/s1600/Add_view_-_Create.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; mta=&quot;true&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg1TE8flvkCIOUyWSuTWQWC1tfnJ3zQ2NqW6pKDFb5KO8I4MdpORqcBsBCmugKq2BJva8ZaAFwJfTDqp3DoXELrgAU5r1C1_VxAkTeLNqqQFDtcFgg6kEtNZGtVB89wAsYsCC_Ad_P2-k4/s1600/Add_view_-_Create.jpg&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;
Fig 14 Add view - Create&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;
2.The page gets created as below with text boxes for each of the fields.&lt;/div&gt;
&lt;div class=&quot;thumb tnone&quot; style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;
&lt;div class=&quot;thumbinner&quot; style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none; width: 510px;&quot;&gt;
&lt;div style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;thumbcaption&quot; style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;
&lt;div style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none; clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjxGmWWlNX00RzlhQPrH8rwRVyFlfc5YnA-UPa4ZJ3n2VTkFFmYAJgeg7bFwVCHw0RA5Kah0jFieIHO-xQ9U1kHH6AahVhHUCT3DH8ODD9GbVPwGQtIz-Jvc0-_mMe3ziWtNXL8q7E5OM8/s1600/Created_Add_view_page.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;301&quot; mta=&quot;true&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjxGmWWlNX00RzlhQPrH8rwRVyFlfc5YnA-UPa4ZJ3n2VTkFFmYAJgeg7bFwVCHw0RA5Kah0jFieIHO-xQ9U1kHH6AahVhHUCT3DH8ODD9GbVPwGQtIz-Jvc0-_mMe3ziWtNXL8q7E5OM8/s320/Created_Add_view_page.jpg&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;
Fig 15 Add view page&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;
3. To add a View for Edit, right click on method Edit and add the page by selecting the options as shown below.&lt;/div&gt;
&lt;div style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;thumb tnone&quot; style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;
&lt;div class=&quot;separator&quot; style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none; clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi9pQHmbLa_KZmi6cX9Uw4VIgakKl1eBuPh3D5ohW11siguV12W_fdlCwIzX2fNI7HCMue0v9CKgXsMjJIOAvD_x46mVz2WvXfmNc8jmfeQGywgsNu-srr_3BW6Ih-Ykst6F1BhxMR9fg0/s1600/Add_view_-_Edit.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; mta=&quot;true&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi9pQHmbLa_KZmi6cX9Uw4VIgakKl1eBuPh3D5ohW11siguV12W_fdlCwIzX2fNI7HCMue0v9CKgXsMjJIOAvD_x46mVz2WvXfmNc8jmfeQGywgsNu-srr_3BW6Ih-Ykst6F1BhxMR9fg0/s1600/Add_view_-_Edit.jpg&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;thumbinner&quot; style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none; width: 262px;&quot;&gt;
&lt;div style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;thumbcaption&quot;&gt;
Fig 16 Add view - Edit&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;
4. In Index page, let us remove the link for details and modify the code to pass id on click of edit.&lt;/div&gt;
&lt;div style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;
With this we have Team Member Info Manager Application working with basic functionalities Create, View and Edit for team members.&lt;/div&gt;
&lt;h2 style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;
&lt;span class=&quot;mw-headline&quot; id=&quot;Validation&quot;&gt;Validation&lt;/span&gt;&lt;/h2&gt;
&lt;div style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;
Code for default validation of the form gets generated with the page. Below is the line of code that gets generated for each input fields. The validation of the input controls is done based on the data type of the object that is bound. &lt;/div&gt;
&amp;lt;%= Html.ValidationMessageFor(model =&amp;gt; model.DateOfJoining)&amp;nbsp;%&amp;gt;&lt;br /&gt;
&lt;div style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;
The validation message gets shown as below.&lt;/div&gt;
&lt;div class=&quot;thumb tnone&quot; style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;
&lt;div class=&quot;thumbinner&quot; style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none; width: 498px;&quot;&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiITK6UTEfNdugtJT_k_hBK_U65pqfhTVc0kulnDIRb2PBQWtULnuERRcYVQTvWHqwIyrINzCRtdSqyHDsobgIJiHJ8I1IjPTWn5liUT_oIg8YCUdm6M4L3MXpSxil-jOTJMfyjFg4w9lk/s1600/Application_validation.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;226&quot; mta=&quot;true&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiITK6UTEfNdugtJT_k_hBK_U65pqfhTVc0kulnDIRb2PBQWtULnuERRcYVQTvWHqwIyrINzCRtdSqyHDsobgIJiHJ8I1IjPTWn5liUT_oIg8YCUdm6M4L3MXpSxil-jOTJMfyjFg4w9lk/s320/Application_validation.jpg&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;thumbcaption&quot;&gt;
Fig 17 Application validation&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
The validation message can be customized by specifying the message as an argument for Validation function.&lt;br /&gt;
&lt;div class=&quot;thumb tnone&quot; style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none; clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjRKO0FC266ylN0LVHEt7c-2J1tZsYvVIveYYqTncvqj882xknI9IzzjUg7NoIm9XMf2PYZGSf6LUJavusmcvLg5KBl1vLftFVH_vCUt7nEJFjsVx95tDjkMlO9RPSIbL4UFGNxB1lqM18/s1600/Validation_code.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;180&quot; mta=&quot;true&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjRKO0FC266ylN0LVHEt7c-2J1tZsYvVIveYYqTncvqj882xknI9IzzjUg7NoIm9XMf2PYZGSf6LUJavusmcvLg5KBl1vLftFVH_vCUt7nEJFjsVx95tDjkMlO9RPSIbL4UFGNxB1lqM18/s320/Validation_code.jpg&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;h2&gt;
&lt;span class=&quot;mw-headline&quot; id=&quot;DataAnnotation_Validation_Support&quot;&gt;DataAnnotation Validation Support&lt;/span&gt;&lt;/h2&gt;
&lt;pre&gt;DataAnnotations provides an easy way to declaratively add validation rules to Model and ViewModel classes within an application, and have automatic binding and UI helper validation support within ASP.NET MVC. ASP.NET MVC 2 includes built-in support for DataAnnotation validations.
&lt;/pre&gt;
&lt;div style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;
The properties of model can be decorate with appropriate validation rules using the DataAnnotation attributes implemented within the System.ComponentModel.DataAnnotations namespace. &lt;/div&gt;
The code looks as follows:&lt;br /&gt;
&lt;pre style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;
 
namespace TeamMemberInfoManager.Models
{
    
    public class TeamMember
    {
        [Required(ErrorMessage=&quot;Please specify First Name&quot;)]
        public String FirstName { get; set; }
 
        public String LastName { get; set; }
 
        [Required(ErrorMessage=&quot;Please specify Employee Number&quot;)]
        [StringLength(10, ErrorMessage = &quot;Must be of 10 characters&quot;)]
        public String EmployeeNumber { get; set; }
 
        public String LoginId { get; set; }
 
        public DateTime DateOfJoining { get; set; }
 
       
    }
}
&lt;/pre&gt;
&lt;div style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;
We also have attributes like Range and RegularExpression for data validation.&lt;/div&gt;
This is how the screen looks with validation message.&lt;br /&gt;
&lt;div class=&quot;thumb tnone&quot; style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;
&lt;div class=&quot;thumbinner&quot; style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none; width: 390px;&quot;&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg5ymY_GjTJw8prLF9uFtTHGviGC5P7E3QoGZxuWH9hqP_ikNRmI_HRKXcpyHWxpYMXOgYfHXKLFt4cRSFuDVJhDNuaZdgo5oFVVmM9aqrxny4sWK1tkNi1VwDRG2AbIKQNlRYqaYmfO7U/s1600/Application_validation.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;226&quot; mta=&quot;true&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg5ymY_GjTJw8prLF9uFtTHGviGC5P7E3QoGZxuWH9hqP_ikNRmI_HRKXcpyHWxpYMXOgYfHXKLFt4cRSFuDVJhDNuaZdgo5oFVVmM9aqrxny4sWK1tkNi1VwDRG2AbIKQNlRYqaYmfO7U/s320/Application_validation.jpg&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;thumbcaption&quot;&gt;
Fig 18 Range and RegularExpression data validation&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;
We can change the display name to a more readable format by adding an attribute [DisplayName] to the model properties. The code looks as follows:&lt;/div&gt;
&lt;pre style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel;
 
namespace TeamMemberInfoManager.Models
{
    
    public class TeamMember
    {
        [Required(ErrorMessage=&quot;Please specify First Name&quot;)]
        [DisplayName(&quot;First Name&quot;)]
        public String FirstName { get; set; }
 
        [DisplayName(&quot;Last Name&quot;)]
        public String LastName { get; set; }
 
        [DisplayName(&quot;Employee Number&quot;)]
        [Required(ErrorMessage=&quot;Please specify Employee Number&quot;)]
        [StringLength(10, ErrorMessage = &quot;Employee Number can not be more thatn 10 characters&quot;)]
        public String EmployeeNumber { get; set; }
 
        [DisplayName(&quot;Login ID&quot;)]
        public String LoginId { get; set; }
 
        [DisplayName(&quot;Joining Date&quot;)]
        public DateTime DateOfJoining { get; set; }       
    }
}
&lt;/pre&gt;
&lt;h1&gt;
&lt;span class=&quot;mw-headline&quot; id=&quot;Guidelines_and_Best_Practices&quot;&gt;Guidelines and Best Practices&lt;/span&gt;&lt;/h1&gt;
&lt;h2&gt;
&lt;span class=&quot;mw-headline&quot; id=&quot;Security&quot;&gt;Security&lt;/span&gt;&lt;/h2&gt;
ASP.NET MVC supports all forms of authentication (Forms, Windows, and Passport) like web forms. We have the option for providing authorization for each action in the control. [Authorize] is an attribute that can be used for authorizing an action in controller. Below is the sample code implementing this.&lt;br /&gt;
&lt;pre&gt;[Authorize]
        public ActionResult CompanySecrets()
        {
            return View();
        }
        [Authorize(Users=&quot;Stephen&quot;)]
        public ActionResult StephenSecrets()
        {
            return View();
        }
        [Authorize(Roles = &quot;Administrators&quot;)]
        public ActionResult AdministratorSecrets()
        {
            return View();
        }
&lt;/pre&gt;
&lt;h2&gt;
&lt;span class=&quot;mw-headline&quot; id=&quot;Filters&quot;&gt;Filters&lt;/span&gt;&lt;/h2&gt;
A filter is an attribute that can be applied to a controller action or an entire controller to modify the way in which the action is executed.&lt;br /&gt;
The ASP.NET MVC framework supports four different types of filters:&lt;br /&gt;
&lt;ul&gt;
&lt;li style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;&lt;a class=&quot;image&quot; href=&quot;http://www.blogger.com/tgtwiki/index.php/File:Range_and_RegularExpression_data_validation.JPG&quot; style=&quot;clear: right; cssfloat: right; float: right; margin-bottom: 1em; margin-left: 1em;&quot;&gt;&lt;/a&gt;&lt;a class=&quot;image&quot; href=&quot;http://www.blogger.com/tgtwiki/index.php/File:Application_validation.JPG&quot; style=&quot;clear: right; cssfloat: right; float: right; margin-bottom: 1em; margin-left: 1em;&quot;&gt;&lt;/a&gt;&lt;a class=&quot;image&quot; href=&quot;http://www.blogger.com/tgtwiki/index.php/File:Add_view_-_Edit.JPG&quot; style=&quot;clear: right; cssfloat: right; float: right; margin-bottom: 1em; margin-left: 1em;&quot;&gt;&lt;/a&gt;&lt;a class=&quot;image&quot; href=&quot;http://www.blogger.com/tgtwiki/index.php/File:Created_Add_view_page.JPG&quot; style=&quot;clear: right; cssfloat: right; float: right; margin-bottom: 1em; margin-left: 1em;&quot;&gt;&lt;/a&gt;&lt;a class=&quot;image&quot; href=&quot;http://www.blogger.com/tgtwiki/index.php/File:Add_view_-_Create.JPG&quot; style=&quot;clear: right; cssfloat: right; float: right; margin-bottom: 1em; margin-left: 1em;&quot;&gt;&lt;/a&gt;&lt;a class=&quot;image&quot; href=&quot;http://www.blogger.com/tgtwiki/index.php/File:Application_Run_wth_TeamMemberIndex_as_the_suffix.JPG&quot; style=&quot;clear: right; cssfloat: right; float: right; margin-bottom: 1em; margin-left: 1em;&quot;&gt;&lt;/a&gt;&lt;a class=&quot;image&quot; href=&quot;http://www.blogger.com/tgtwiki/index.php/File:Add_view_-_List.JPG&quot; style=&quot;clear: right; cssfloat: right; float: right; margin-bottom: 1em; margin-left: 1em;&quot;&gt;&lt;/a&gt;&lt;a class=&quot;image&quot; href=&quot;http://www.blogger.com/tgtwiki/index.php/File:Action_index.JPG&quot; style=&quot;clear: right; cssfloat: right; float: right; margin-bottom: 1em; margin-left: 1em;&quot;&gt;&lt;/a&gt;&lt;a class=&quot;image&quot; href=&quot;http://www.blogger.com/tgtwiki/index.php/File:Controllers_folder.JPG&quot; style=&quot;clear: right; cssfloat: right; float: right; margin-bottom: 1em; margin-left: 1em;&quot;&gt;&lt;/a&gt;&lt;a class=&quot;image&quot; href=&quot;http://www.blogger.com/tgtwiki/index.php/File:Add_New_Item.JPG&quot; style=&quot;clear: right; cssfloat: right; float: right; margin-bottom: 1em; margin-left: 1em;&quot;&gt;&lt;/a&gt;&lt;a class=&quot;image&quot; href=&quot;http://www.blogger.com/tgtwiki/index.php/File:ASP_.Net_MVC_Home_Page.JPG&quot; style=&quot;clear: right; cssfloat: right; float: right; margin-bottom: 1em; margin-left: 1em;&quot;&gt;&lt;/a&gt;&lt;a class=&quot;image&quot; href=&quot;http://www.blogger.com/tgtwiki/index.php/File:ASP_.Net_MVC_Home_Page.JPG&quot; style=&quot;clear: right; cssfloat: right; float: right; margin-bottom: 1em; margin-left: 1em;&quot;&gt;&lt;/a&gt;&lt;a class=&quot;image&quot; href=&quot;http://www.blogger.com/tgtwiki/index.php/File:HTTP_request_flow.JPG&quot; style=&quot;clear: right; cssfloat: right; float: right; margin-bottom: 1em; margin-left: 1em;&quot;&gt;&lt;/a&gt;&lt;a class=&quot;image&quot; href=&quot;http://www.blogger.com/tgtwiki/index.php/File:Model-View-Controller_concept.JPG&quot; style=&quot;clear: right; cssfloat: right; float: right; margin-bottom: 1em; margin-left: 1em;&quot;&gt;&lt;/a&gt;Authorization filters - Authorization filters are used to implement authentication and authorization for controller actions. Authorization filters implements IAuthorizationFilter attribute. Authorize filter is an example of an Authorization filter.&lt;/li&gt;
&lt;li&gt;Action filters - Action filters contain logic that is executed before and after a controller action executes. Action filters implements the IActionFilter attribute. We can use an action filter, for instance, to modify the view data that a controller action returns.&lt;/li&gt;
&lt;li style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;Result filters - Result filters contain logic that is executed before and after a view result is executed. Result filters implements the IResultFilter attribute. This can be used to modify a view result right before the view is rendered to the browser.&lt;/li&gt;
&lt;li style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;Exception filters - Exception filters are the last type of filter to run. We can use an exception filter to handle errors raised by either controller actions or controller action results. We also can use exception filters to log errors. Exception filters Implements the IExceptionFilter attribute. &lt;/li&gt;
&lt;/ul&gt;
&lt;div style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;
Filters are executed in the order listed above. For example, authorization filters are always executed before action filters and exception filters are always executed after every other type of filter.&lt;/div&gt;
&lt;h2 style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;
&lt;span class=&quot;mw-headline&quot; id=&quot;ASP.NET_MVC_Areas&quot;&gt;ASP.NET MVC Areas&lt;/span&gt;&lt;/h2&gt;
&lt;div style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;
To accommodate large projects, ASP.NET MVC lets us partition Web applications into smaller units that are referred to as areas. Areas provide a way to separate a large MVC Web application into smaller functional groupings. An area is effectively an MVC structure inside an application. An application could contain several MVC structures (areas). For more informatino, refer &lt;a class=&quot;external text&quot; href=&quot;http://msdn.microsoft.com/en-us/library/ee671793.aspx&quot; rel=&quot;nofollow&quot;&gt;ASP.NET MVC Areas&lt;/a&gt; to learn more.&lt;/div&gt;
&lt;h2&gt;
&lt;span class=&quot;mw-headline&quot; id=&quot;Deciding_When_to_Create_an_MVC_Application&quot;&gt;Deciding When to Create an MVC Application&lt;/span&gt;&lt;/h2&gt;
One must consider carefully whether to implement a Web application by using either the ASP.NET MVC framework or the ASP.NET Web Forms model. The MVC framework does not replace the Web Forms model; we can use either framework for Web applications. (If we have existing Web Forms-based applications, these continue to work exactly as they always have.) We can also have application developed using both web forms and ASP.NET MVC.&lt;br /&gt;
Before we decide to use the MVC framework or the Web Forms model for a specific Web site, weigh the advantages of each approach.&lt;br /&gt;
&lt;h3&gt;
&lt;span class=&quot;mw-headline&quot; id=&quot;Advantages_of_a_MVC-Based_Web_Application&quot;&gt;Advantages of a MVC-Based Web Application&lt;/span&gt;&lt;/h3&gt;
The ASP.NET MVC framework offers the following advantages:&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;It makes it easier to manage complexity by dividing an application into the model, the view, and the controller. &lt;/li&gt;
&lt;li&gt;It does not use view state or server-based forms. This makes the MVC framework ideal for developers who want full control over the behavior of an application. &lt;/li&gt;
&lt;li style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;It uses a Front Controller pattern that processes Web application requests through a single controller. This enables you to design an application that supports a rich routing infrastructure. &lt;/li&gt;
&lt;li&gt;It provides better support for test-driven development (TDD). &lt;/li&gt;
&lt;li style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;It works well for Web applications that are supported by large teams of developers and Web designers who need a high degree of control over the application behavior.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
&lt;span class=&quot;mw-headline&quot; id=&quot;Advantages_of_a_Web_Forms-Based_Web_Application&quot;&gt;Advantages of a Web Forms-Based Web Application&lt;/span&gt;&lt;/h3&gt;
The Web Forms-based framework offers the following advantages:&lt;br /&gt;
&lt;ul&gt;
&lt;li style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;It supports an event model that preserves state over HTTP, which benefits line-of-business Web application development. The Web Forms-based application provides dozens of events that are supported in hundreds of server controls. &lt;/li&gt;
&lt;li&gt;It uses a Page Controller pattern that adds functionality to individual pages. &lt;/li&gt;
&lt;li&gt;It uses view state or server-based forms, which can make managing state information easier. &lt;/li&gt;
&lt;li style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;It works well for small teams of Web developers and designers who want to take advantage of the large number of components available for rapid application development. &lt;/li&gt;
&lt;li style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;In general, it is less complex for application development, because the components (the &lt;b&gt;Page&lt;/b&gt; class, controls, and so on) are tightly integrated and usually require less code than the MVC model. &lt;/li&gt;
&lt;li&gt;As it is a classic way of implementing web application, required time for learning is less.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
&lt;span class=&quot;mw-headline&quot; id=&quot;Other_Best_practices&quot;&gt;Other Best practices&lt;/span&gt;&lt;/h2&gt;
&lt;ul style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;&lt;div style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;
Demo code should not be part of production application. So delete AccountController demo code that gets generated on creating MVC application.&lt;/div&gt;
&lt;/li&gt;
&lt;li style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;Isolate controllers from external world&lt;br /&gt;&lt;ul&gt;
&lt;li style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;HttpContext&lt;/li&gt;
&lt;li style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;Data Access Classes&lt;/li&gt;
&lt;li style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;Configuration management&lt;/li&gt;
&lt;li style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;Logging&lt;/li&gt;
&lt;li style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;Clock&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;Never use magic strings.&lt;br /&gt;&lt;ul&gt;
&lt;li style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;Never use ViewData[“key”], but always create a ViewModel per each View, and use strongly-typed views ViewPage&amp;lt;ViewModel&amp;gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Pay attention to verbs&lt;br /&gt;&lt;ul&gt;
&lt;li&gt;Show data in GET.&lt;/li&gt;
&lt;li&gt;Modify data in POST.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Have DataModel&amp;nbsp;!= View Model&lt;br /&gt;&lt;ul&gt;
&lt;li style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;Data Model contains data and behavior; it is hierarchical and contains complex types.&lt;/li&gt;
&lt;li style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;View Model contains only data; it is flat and contains only string data types. &lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;Do not use code behind.&lt;/li&gt;
&lt;li style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;Do not have logic in views.&lt;br /&gt;&lt;ul&gt;
&lt;li style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none;&quot;&gt;If and Foreach are allowed in view and accomplish this logic with HtmlHelper class.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://technicalwizardry.blogspot.com/feeds/6571162366897676555/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4930197226974329220/6571162366897676555' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4930197226974329220/posts/default/6571162366897676555'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4930197226974329220/posts/default/6571162366897676555'/><link rel='alternate' type='text/html' href='http://technicalwizardry.blogspot.com/2013/04/this-page-provides-guidance-and-best.html' title='ASP.NET MVC Best practise'/><author><name>lloyd</name><uri>http://www.blogger.com/profile/04794204354889644869</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgA5q0xlK7umtyyBWFkMQwZQOonP5LuVNL3QnnfiZ409SLryDamMSxGdyRR_LciyL1hZR4-DjkZSY7MmTEMdAChFXno-bc9lW3Lo5xV3dYQvdK11xedJ3oJG1_C6fxBgXE/s220/IMG_0236.jpg'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhQaBAIewJD1B18SrQQN_UzjJAH8EgKUUzyhrBAn_FFTaFX9ZKtFL7G4xibvufKSbGm5TnUI2PaO1pp6Z3lqGZcSCz4MXy8NUQadECvJtDvRIhdQYh1AkHn5oF8jF-FUjSW2GbUZ2vTlBc/s72-c/ASP_NET_frameworks.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4930197226974329220.post-3684805931293825669</id><published>2013-04-02T04:34:00.000-07:00</published><updated>2013-04-03T00:29:14.359-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Advanced WCF"/><category scheme="http://www.blogger.com/atom/ns#" term="C#"/><category scheme="http://www.blogger.com/atom/ns#" term="technical"/><category scheme="http://www.blogger.com/atom/ns#" term="WCF"/><category scheme="http://www.blogger.com/atom/ns#" term="WCF C# versioning DotNet"/><category scheme="http://www.blogger.com/atom/ns#" term="WCF tuning"/><title type='text'>Windows Security for WCF Intranet Applications</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
Pattern Description&lt;/h3&gt;
&lt;br /&gt;
In an intranet scenario where the WCF service serves .NET clients, it would be ideal to take advantage of the existing Windows security (that is, Kerberos authentication and Active Directory role base authorization) infrastructure. This pattern explains how to configure a WCF service to do just that. &lt;br /&gt;
&lt;br /&gt;
In this pattern we host the service in IIS with “wsHttpBinding” binding. Note that the service could also be hosted in a Windows Service process using the “NetTCPBinding.” Although TCP provides better performance over HTTP, however, IIS provides many benefits over Windows Service such as on-demand service activation, process recycling, etc. Also note that in Windows 2008 and IIS 7, bindings other than “*HttpBinding” can be hosed on Windows Activation Service (WAS). &lt;br /&gt;
&lt;br /&gt;
Using this pattern, the caller’s Windows identity will flow to the service. Who the “caller” is, depends on the client type (rich/ASP.NET/another WCF service) and whether or not impersonation occurs: &lt;br /&gt;
&lt;br /&gt;
Rich client (Winform/WPF): The logon user identity unless the app impersonates a different user in code. &lt;br /&gt;
ASP.NET client: The process identity (App Pool identity), unless the app impersonates the original caller. &lt;br /&gt;
Another WCF service: The service account that the service is running on, unless the WCF is impersonating the original caller. &lt;br /&gt;
In the sample implementation in this document, we follow a “Trusted Sub System” model where the ASP.NET client application does not impersonate the original caller.The sample, however, shows how to send the original caller’s identity in the message header. &lt;br /&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
Pattern Flow Description&lt;/h3&gt;
The service requires that all communications between it and its clients are encrypted. It also requires that the clients must have a Windows identity and reside on the same domain as the service or a trusting domain. The caller’s Window’s identity flows to the service. The service authenticates the caller and verifies if the caller is authorized to access the service’s methods/properties. If the service needs to call other resources such a database that require Windows authentication the service will present its process identity (service account if not self hosted). &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
Implementation Details&lt;/h3&gt;
&lt;h4 style=&quot;text-align: left;&quot;&gt;
Description&lt;/h4&gt;
&lt;br /&gt;
The following steps show how to configure the service and its client(s) to implement this pattern: &lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;1.Create a “.svc” file that specifies the service type and copy it to the root of your Virtual Directory: &lt;br /&gt;
&lt;code&gt;&lt;br /&gt;&amp;lt;%@ ServiceHost Language = &quot;C#&quot; Service = &quot;WCF.Demo.Service&quot;%&amp;gt; &lt;/code&gt;&lt;br /&gt;
&lt;br /&gt;
2.In the “web.config” file add a “Services” section that sets the binding as “wsHttpBinding” and the service’s end point address: &lt;br /&gt;
&lt;pre&gt;&amp;lt;services&amp;gt;
        &amp;lt;service name=&quot; WCF.Demo.Servce&quot;&amp;gt;
               &amp;lt;endpoint address=“http://localhost/MYSITE&quot;
                       binding=“wsHttpBinding&quot; bindingConfiguration=&quot;wsHttpBindingWindows&quot;
                       contract=“WCF.Demo.IService&quot; /&amp;gt;
          &amp;lt;/service&amp;gt;
&amp;lt;/services&amp;gt; 
&lt;/pre&gt;
&lt;br /&gt;
3.In the “web.config” file add a “Binding” section that sets “Security Mode” to “Message” and “Client Credential Type” to “Windows”:&lt;br /&gt;
&lt;pre&gt;&amp;lt;bindings&amp;gt;
      &amp;lt;wsHttpBinding&amp;gt;
        &amp;lt;binding name=&quot;wsHttpBindingWindows&quot;&amp;gt;
          &amp;lt;reliableSession enabled=&quot;false&quot; /&amp;gt;
          &amp;lt;security mode=&quot;Message&quot;&amp;gt;
            &amp;lt;transport clientCredentialType=&quot;Windows&quot; /&amp;gt;
            &amp;lt;message clientCredentialType=&quot;Windows&quot; negotiateServiceCredential=&quot;false&quot;
              establishSecurityContext=&quot;false&quot; /&amp;gt;
          &amp;lt;/security&amp;gt;
        &amp;lt;/binding&amp;gt;
      &amp;lt;/wsHttpBinding&amp;gt;
    &amp;lt;/bindings&amp;gt;
&lt;/pre&gt;
4.Add logic for your service.&lt;br /&gt;
&lt;h4&gt;
&lt;span class=&quot;mw-headline&quot; id=&quot;Client&quot;&gt;Client&lt;/span&gt;&lt;/h4&gt;
In Visual Studio set a “Service Reference” to the service you created in the previous step. This will create a service proxy and will add appropriate sections in the config file that specifies server’s end point address, binding, authentication requirements, and so on.. &lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
1. In the config file, find the “Identity” sub section under the “Client” section and change:&lt;br /&gt;
&lt;pre&gt;&amp;lt;userPrincipalName value=&quot;MyServiceAcct&quot; /&amp;gt;
 
To
 
&amp;lt;servicePrincipalName value=&quot;MyServiceAcct&quot; /&amp;gt;    
&lt;/pre&gt;
2.Create an instance of the service proxy and call its methods.&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;h2&gt;
&lt;span class=&quot;mw-headline&quot; id=&quot;Examples&quot;&gt;Examples&lt;/span&gt;&lt;/h2&gt;
&lt;h3&gt;
&lt;span class=&quot;mw-headline&quot; id=&quot;Client_2&quot;&gt;Client&lt;/span&gt;&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Client app is an ASP.NET application.&lt;/li&gt;
&lt;li&gt;The ASP.NET’s app pool is set to use a custom domain account that has an SPN mapping.&lt;/li&gt;
&lt;li&gt;The ASP.NET’s app pool is authorized to call the service.&lt;/li&gt;
&lt;li&gt;The ASP.NET app is configured in IIS to use “Windows Integrated Security”&lt;/li&gt;
&lt;li&gt;The ASP.NET app is set to use coarse authorization in “web.config”:&lt;/li&gt;
&lt;/ul&gt;
&lt;pre&gt;&amp;lt;allow roles=&quot;DOMAIN\USERGROUPS&quot; /&amp;gt;
&amp;lt;deny users=&quot;*&quot; /&amp;gt;
&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;The ASP.NET app uses finer grain security in code:&lt;/li&gt;
&lt;/ul&gt;
&lt;pre&gt;if (User.IsInRole(&quot;DOMAIN\\USERGROUPS&quot;)) {//call service}
&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;The ASP.NET does not impersonate the caller.&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;
&lt;span class=&quot;mw-headline&quot; id=&quot;Service_2&quot;&gt;Service&lt;/span&gt;&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;The WCF service is hosted in IIS 6.0.&lt;/li&gt;
&lt;li&gt;The service’s app pool is set to use a custom domain account that has an SPN mapping.&lt;/li&gt;
&lt;li&gt;The service’s app pool identity has been given access to SQL Server.&lt;/li&gt;
&lt;li&gt;The service uses Windows Integrated Security to connect to SQL Server.&lt;/li&gt;
&lt;li&gt;The service uses “wsHttpBinding” with message security and Kerberos authentication (see service config file).&lt;/li&gt;
&lt;li&gt;The service only trusts a group that contains the ASP.NET’s app pool identity. It uses .NET authorization techniques (for this demo all three methods are used for illustration: Direct Role checking, Imperative, Declarative) to ensure that the caller belongs to an authorized group.&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;
&lt;span class=&quot;mw-headline&quot; id=&quot;SQL_Server&quot;&gt;&lt;a class=&quot;mw-redirect&quot; href=&quot;http://www.blogger.com/tgtwiki/index.php/SQL&quot; title=&quot;SQL&quot;&gt;SQL&lt;/a&gt; Server&lt;/span&gt;&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a class=&quot;mw-redirect&quot; href=&quot;http://www.blogger.com/tgtwiki/index.php/SQL&quot; title=&quot;SQL&quot;&gt;SQL&lt;/a&gt; Server is configured to use Windows Integrated Security&lt;/li&gt;
&lt;li&gt;Only the WCF Service’s app pool identity has been given access to SQL Server and tables. &lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
&lt;span class=&quot;mw-headline&quot; id=&quot;Sample_Code&quot;&gt;Sample Code&lt;/span&gt;&lt;/h3&gt;
&lt;h4&gt;
&lt;span class=&quot;mw-headline&quot; id=&quot;Client_Code:_Config_File&quot;&gt;Client Code: Config File&lt;/span&gt;&lt;/h4&gt;
&lt;b&gt;Security section&lt;/b&gt;&lt;br /&gt;
&lt;pre&gt;&amp;lt;authentication mode=&quot;Windows&quot;/&amp;gt;
  &amp;lt;authorization&amp;gt;
      &amp;lt;allow roles=&quot;DOMAIN\USERGROUPS&quot; /&amp;gt;
      &amp;lt;deny users=&quot;*&quot; /&amp;gt;
&amp;lt;/authorization
 
&lt;/pre&gt;
&lt;b&gt;Service Proxy Section&lt;/b&gt; &lt;br /&gt;
Once the client creates a proxy for the service, Visual Studio automatically adds a “Service Model” section to the client’s config file that specifies things such as the end point address, binding, security, and so on.. For clarity, some section has been removed. The only thing to note here is to make sure you change “&lt;strong&gt;userPrincipalName&lt;/strong&gt;” to “&lt;strong&gt;servicePrincipalName&lt;/strong&gt;”:&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;pre&gt;&amp;lt;system.serviceModel&amp;gt;
 &amp;lt;client&amp;gt;
    &amp;lt;endpoint address=&lt;a href=&quot;http://localhost/MYSITE/PAGE.SVC&quot;&gt;http://LOCALHOST/MYSITE/PAGE.SVC&lt;/a&gt; 
                   binding=&quot;wsHttpBinding&quot; 
                   bindingConfiguration=&quot;WSHttpBinding_IService&quot;     
                   contract=&quot;WCFProxy.IService&quot; 
                   name=&quot;WSHttpBinding_IService&quot;&amp;gt;
     &amp;lt;identity&amp;gt;
  &amp;lt;servicePrincipalName   
             value=&quot;SERVICEACCOUNT&quot;/&amp;gt;
     &amp;lt;/identity&amp;gt;
   &amp;lt;/endpoint&amp;gt;
 &amp;lt;/client&amp;gt;
&amp;lt;/system.serviceModel&amp;gt;
&lt;/pre&gt;
&lt;br /&gt;
&lt;b&gt;ASP.NET Code&lt;/b&gt;&lt;br /&gt;
&lt;pre&gt;    protected void Button1_Click(object sender, EventArgs e)
    {
        // Perform a Direct Role check to ensure the caller 
        // is authorized to access the web application.
        if (User.IsInRole(&quot;DOMAIN\USERGROUPS&quot;))
        {
            using (WCFProxy.ServiceClient svc = new 
                  WCFProxy.ServiceClient())
            {
                try
                {
      // Call the service
                    Label1.Text = 
                    svc.ConnectToSQLServer().ToString();
                }
                catch (Exception ex)
                {
                   Label1.Text = &quot;Error: &quot; + ex.Message;
                }
            }
        }
        else
        {
            Label1.Text = &quot;Error: &quot; + &quot;Access denied&quot;;
        }
   }
&lt;/pre&gt;
&lt;h4&gt;
&lt;span class=&quot;mw-headline&quot; id=&quot;Service_Code:_Config_File&quot;&gt;Service Code: Config File&lt;/span&gt;&lt;/h4&gt;
The appropriate sections in the service’s configuration file. It specifies &lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;pre&gt;   &amp;lt;bindings&amp;gt;
      &amp;lt;wsHttpBinding&amp;gt;
        &amp;lt;binding name=&quot;wsHttpBindingWindows&quot;&amp;gt;
          &amp;lt;reliableSession enabled=&quot;false&quot; /&amp;gt;
          &amp;lt;security mode=&quot;Message&quot;&amp;gt;
            &amp;lt;transport clientCredentialType=&quot;Windows&quot; /&amp;gt;
            &amp;lt;message clientCredentialType=&quot;Windows&quot; 
              negotiateServiceCredential=&quot;false&quot;
              establishSecurityContext=&quot;false&quot; /&amp;gt;
          &amp;lt;/security&amp;gt;
        &amp;lt;/binding&amp;gt;
      &amp;lt;/wsHttpBinding&amp;gt;
    &amp;lt;/bindings&amp;gt;
 
    &amp;lt;services&amp;gt;
      &amp;lt;service behaviorConfiguration=&quot;ServiceBehavior&quot; 
               name=&quot;Service&quot;&amp;gt;
        &amp;lt;endpoint address=&quot;HTTP://LOCALHOST/MYSITE/PAGE.svc&quot;
          binding=&quot;wsHttpBinding&quot; 
          bindingConfiguration=&quot;wsHttpBindingWindows&quot;
          contract=&quot;IService&quot; /&amp;gt;
      &amp;lt;/service&amp;gt;
    &amp;lt;/services&amp;gt;
 
    &amp;lt;behaviors&amp;gt;
      &amp;lt;serviceBehaviors&amp;gt;
        &amp;lt;behavior name=&quot;ServiceBehavior&quot;&amp;gt;
          &amp;lt;serviceMetadata httpGetEnabled=&quot;true&quot; /&amp;gt;
          &amp;lt;serviceDebug includeExceptionDetailInFaults=&quot;true&quot; /&amp;gt;
                &amp;lt;/behavior&amp;gt;
      &amp;lt;/serviceBehaviors&amp;gt;
    &amp;lt;/behaviors&amp;gt;
&lt;/pre&gt;
&lt;br /&gt;
&lt;b&gt;Service Methods&lt;/b&gt; &lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
The following methods show how the service is implemented. What the service does is not important here. What is important is illustrating the principal of “Trusted Sub Systems.” These include:&lt;br /&gt;
The service performs authorization to ensure the caller is authorized before executing methods and accessing SQL Server. In this case, the service trusts the calling application’s service account (app pool id). &lt;br /&gt;
This sample shows how to implement authorization in the service using three methods of authorization that .NET support namely: &lt;strong&gt;“Direct,” “Imperative,” and “Declarative.”&lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
Only the service’s app pool identity is given access to &lt;b&gt;SQL&lt;/b&gt; Server.&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;pre&gt;    // Declarative Authorization, make sure the caller belongs to &quot;DOMAIN\USERGROUPS&quot; group.
    // Note that ASP.NET’s app pool identiy should belong to 
    // this group. 
    [PrincipalPermission(SecurityAction.Demand, Role = 
                                        &quot;DOMAIN\USERGROUPS&quot;)]
    public bool ConnectToSQLServer()
    {
        // Windows integrated security is used to connect to
        // SQL Server. The service’s app pool id is passed
        // to SQL Server.
        string conn = &quot;Data Source = SQLEXPRESS01; Initial Catalog = 
               Northwind; Integrated Security = SSPI;&quot;;
        
        SqlCommand command = new SqlCommand();
        command.Connection = new SqlConnection(conn);
        command.Connection.Open();
        command.Connection.Close();
 
        return true;
    }
 
 
public List&amp;lt;string&amp;gt; GetEndPointsDetails()
{
        // Use direct Role check for this method
     // make sure the caller belongs to    
     // &quot;DOMAIN\USERGROUPS&quot; group.
     // Note that ASP.NET’s app pool identiy should belong to 
     // this group. 
        if (Thread.CurrentPrincipal.IsInRole(&quot;DOMAIN\USERGROUPS&quot;))
        {
            ServiceHost host = new ServiceHost(typeof(Service));
            List&amp;lt;string&amp;gt; list = new List&amp;lt;string&amp;gt;();
 
            Foreach             
            (System.ServiceModel.Description.ServiceEndpoint 
                    endPoint in host.Description.Endpoints)
            {
                list.Add(&quot;Logical Address=&quot; + endPoint.Address + 
                &quot;    &quot; + &quot;Physical Address=&quot; + 
                endPoint.ListenUri);
            }
 
            return list;
        }
        else
        {
            //throw exception
            throw new FaultException(&quot;Authorization failed&quot;);
        }
           }
 
          public string GetThreadIdentity()
    {
        // Imperative Authorization. The ASP.NET 
        // app pool identity must belong to at least
        // one of the fictious “BuyersAdmin” or 
        // “SupplyAdmins” groups.
        PrincipalPermission devPermission = new 
        PrincipalPermission(null, &quot;DOMAIN\USERGROUPS&quot;);
        PrincipalPermission adminPermission = new 
        PrincipalPermission(null, &quot;DOMAIN\USERGROUPS2&quot;);
 
        // User must be in at least one of the authorized groups
        devPermission.Union(adminPermission).Demand();
        return Thread.CurrentPrincipal.Identity.Name;
&lt;/pre&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://technicalwizardry.blogspot.com/feeds/3684805931293825669/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4930197226974329220/3684805931293825669' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4930197226974329220/posts/default/3684805931293825669'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4930197226974329220/posts/default/3684805931293825669'/><link rel='alternate' type='text/html' href='http://technicalwizardry.blogspot.com/2013/04/windows-security-for-wcf-intranet.html' title='Windows Security for WCF Intranet Applications'/><author><name>lloyd</name><uri>http://www.blogger.com/profile/04794204354889644869</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgA5q0xlK7umtyyBWFkMQwZQOonP5LuVNL3QnnfiZ409SLryDamMSxGdyRR_LciyL1hZR4-DjkZSY7MmTEMdAChFXno-bc9lW3Lo5xV3dYQvdK11xedJ3oJG1_C6fxBgXE/s220/IMG_0236.jpg'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4930197226974329220.post-83889733435914015</id><published>2013-03-27T02:21:00.000-07:00</published><updated>2013-04-03T00:29:14.365-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="C#"/><category scheme="http://www.blogger.com/atom/ns#" term="Interlocked"/><category scheme="http://www.blogger.com/atom/ns#" term="technical"/><category scheme="http://www.blogger.com/atom/ns#" term="threading"/><title type='text'>C# threading advanced concepts</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;C# has definetly made it easy to work with threads considering how difficult they are in C , C++ One of the requirements we had to work on was to perform a task A by spawning configurable amount of threads. Once and only once task A was done we should proceed with Tasks B, C, D. &lt;br /&gt;
&lt;br /&gt;
To implement this i had used the Monitor.Pulse and Monitor.Wait methods. Here is a snapshot of the implementation. &lt;br /&gt;
&lt;br /&gt;
&lt;code&gt;&lt;pre&gt;public static class mylocker 
{ 
  public static int runningWorkers = 5; 
} 
public class PriceManager 
{ 
  private static object workerLocker = new object(); 
  private Handler handler; 
  private void StartXHandler_Threads() 
  { 
    this.handler= new Handler (workerLocker); 
    for (int i = 0; i &amp;lt; mylocker.runningWorkers; i++) 
    { 
      ThreadPool.QueueUserWorkItem(new WaitCallback(o =&amp;gt; new Handler().ProcessActivity())); 
    } 
    lock (workerLocker) 
    { 
      while (mylocker.runningWorkers &amp;gt; 0) Monitor.Wait(workerLocker); 
    } 
  }  
} 

Public class Handler 
{ 
  private static object workerLocker; 
  Public Handler(object _workerLocker): this() 
  { 
    workerLocker = _workerLocker; 
  } 
  Public void ProcessActivity() 
  { 
    //---&amp;gt; Do SOME WORK 

    //Once Done, Decrement the thread count and pulse to the main application call that 
    // we are done 

    lock (workerLocker) 
    { 
      mylocker.runningWorkers--; 
      Monitor.Pulse(workerLocker); 
    } 
  } 
} 
&lt;/pre&gt;&lt;/code&gt;&lt;br /&gt;
This for most part works fine until we were told that even putting a lock and decrementing the count is not thread safe and the lock on object can sometime be broken, apparently there is a class in C# called the Interlocked class that allows you decrement, increment in a safe manner. &lt;br /&gt;
&lt;br /&gt;
Some highlights of this class are &quot;The Interlocked class works by requesting that the CLR and Operating System increment (or, decrement, etc.) the number atomically. &lt;br /&gt;
&lt;br /&gt;
The .NET Framework’s Interlocked class taps right into this OS functionality, thus allowing you to avoid errors when two threads attempt an increment at the same time.&quot; You can read up more from this nicely written article. &lt;br /&gt;
&lt;a href=&quot;http://geekswithblogs.net/BlackRabbitCoder/archive/2012/08/09/c.net-little-wonders-interlocked-increment-decrement-and-add.aspx&quot;&gt;Interlocked Classes and Use&lt;/a&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://technicalwizardry.blogspot.com/feeds/83889733435914015/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4930197226974329220/83889733435914015' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4930197226974329220/posts/default/83889733435914015'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4930197226974329220/posts/default/83889733435914015'/><link rel='alternate' type='text/html' href='http://technicalwizardry.blogspot.com/2013/03/c-threading-advanced-concepts.html' title='C# threading advanced concepts'/><author><name>lloyd</name><uri>http://www.blogger.com/profile/04794204354889644869</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgA5q0xlK7umtyyBWFkMQwZQOonP5LuVNL3QnnfiZ409SLryDamMSxGdyRR_LciyL1hZR4-DjkZSY7MmTEMdAChFXno-bc9lW3Lo5xV3dYQvdK11xedJ3oJG1_C6fxBgXE/s220/IMG_0236.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4930197226974329220.post-2126477751406104144</id><published>2012-05-31T07:25:00.001-07:00</published><updated>2013-04-03T00:29:14.356-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="sql tuning"/><category scheme="http://www.blogger.com/atom/ns#" term="technical"/><title type='text'>SQL Server Query Tuning</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
You can definitely find a lot of articles out on the internet showing 
different techniques for optimization of queries. What follows is 
actual implementation or rather sequence of steps that i did to tune the
 database for improved performance and speed.&lt;br /&gt;&lt;br /&gt;The first step is 
to find which of the queries are slow performing. Most of the times it 
is only after the client or end user starts complaining that the 
application is slow.&lt;br /&gt;The right way to go about this is to think about
 performance when you go about designing the database, tables, stored 
procedures and indexes.&lt;br /&gt;&lt;br /&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
SETTING AND CHOOSING INDEXES&lt;/h3&gt;
There are only two types of indexes available Clustered and Non clustered indexes.&lt;br /&gt;&lt;br /&gt;
There
 can only be one clustered index and that is how the actual data will be
 stored in the database. You can have several non-clustered indexes 
according to MSDN the maximum number is around 249 indexes.&lt;br /&gt;To give a
 real world explanation of clustered and non-clustered index, think of a
 yellow book. The index at the end is the non-clustered index, it gives a
 pointer to the where you can find the actual data.&lt;br /&gt;&lt;br /&gt;Some of the golden rules while going about optimization are&lt;br /&gt;&lt;br /&gt;(1)&lt;span style=&quot;font-weight: bold;&quot;&gt;Selectivity&lt;/span&gt;
 A good rule for non-clustered index is the percentage of records that 
are unique, the higher the value the better the selectivity. For example
 a column of type boolean will have good selectivity since it will have a
 50% unique selectivity on the account of possible values being True or 
False.&lt;br /&gt;Keep in mind that setting a non-clustered index might not 
always be better since it will have to perform an actual lookup on the 
clustered index to find the actual data.&lt;br /&gt;If the index is going to perform multiple lookups then there can be instances where an actual table scan might perform better.&lt;br /&gt;&lt;br /&gt;(2)&lt;span style=&quot;font-weight: bold;&quot;&gt;Exception to Selectivity&lt;/span&gt;
 When foreign keys come into picture the rule of selectivity can be 
thrown out of the window. Why foreign keys and not other columns is 
because it improves the join performance as it performs a MERGE JOIN 
internally. More on the different types of joins later.&lt;br /&gt;This brings 
up the point that selectivity is not everything,and the question you 
should ask is how often is this field going to be used.&lt;br /&gt;&lt;br /&gt;(3)&lt;span style=&quot;font-weight: bold;&quot;&gt;Index decrease performance&lt;/span&gt;
 Though a well designed index speeds up performance they can be slow 
while trying to update data. Anytime data is modified any index related 
to that data also needs to be updated.. So what that means is that if you have a clustered index on an integer and there are constant updates to this field. Sql server will have to sort this data.&lt;br /&gt;
Internally sql server stores the data in one format only, but i uses a Array of sort internally storing the order of the field. Also if you keep changing the clustered index then this Array is sorted again, so it adds to performance issues.&lt;br /&gt;&lt;br /&gt;(4)&lt;span style=&quot;font-weight: bold;&quot;&gt;Don&#39;t Accept the Default Clustered index&lt;/span&gt; when you define a key as primary by default SQL Server sets this column as a clustered index.&lt;br /&gt;A
 clustered index should be defined on a column that participates in a 
range query for example a column that takes part in a between, &amp;lt;, 
&amp;gt;, MAX, MIN and COUNT aggregates. The reason why this works well is 
because the query can do directly to the data and keep reading till it 
gets to the end.&lt;br /&gt;&lt;br /&gt;(5)&lt;span style=&quot;font-weight: bold;&quot;&gt;Keep Index Keys Short&lt;/span&gt;&lt;br /&gt;The
 larger an index key is, the harder a database has to work to use the 
index. For instance, an integer key is smaller in size then a character 
field for holding 100 characters. In particular, keep clustered indexes 
as short as possible.&lt;br /&gt;There are several approaches to keeping an 
index key short. Try to limit the index to as few columns as possible. 
While composite indexes are useful and can sometimes optimize a query, 
they are also larger and cause more disk reads for the database. Choose a
 data type for an index column with less number of bytes required for 
each data type. Integer keys are small and easy for the database to 
compare. In contrast, strings require a character-by-character 
comparison.&lt;br /&gt;&lt;br /&gt;As a rule of thumb, try to avoid using character 
columns in an index. Integer columns will always have an advantage over 
character fields in ability to boost the performance of a query.&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://technicalwizardry.blogspot.com/feeds/2126477751406104144/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4930197226974329220/2126477751406104144' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4930197226974329220/posts/default/2126477751406104144'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4930197226974329220/posts/default/2126477751406104144'/><link rel='alternate' type='text/html' href='http://technicalwizardry.blogspot.com/2012/05/sql-server-query-tuning.html' title='SQL Server Query Tuning'/><author><name>lloyd</name><uri>http://www.blogger.com/profile/04794204354889644869</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgA5q0xlK7umtyyBWFkMQwZQOonP5LuVNL3QnnfiZ409SLryDamMSxGdyRR_LciyL1hZR4-DjkZSY7MmTEMdAChFXno-bc9lW3Lo5xV3dYQvdK11xedJ3oJG1_C6fxBgXE/s220/IMG_0236.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4930197226974329220.post-4392422962147590678</id><published>2012-05-31T07:09:00.001-07:00</published><updated>2013-04-03T00:29:14.361-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="technical"/><title type='text'>IE BOX MODEL</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
IE 7 Onwards uses the W3C box model and other browser too. IE 6 uses the
 IE box model. The IE box model includes padding, border in its 
calculation of its width. The W3C model does not and calculates it 
separately. This is the main reason for alignment problems.&lt;br /&gt;
IE box model, a box having a width of 100px, with 2px padding on each 
side, a 3px border, and 7px margin on each side, will have a visible 
width of 114px.&lt;br /&gt;
&lt;br /&gt;
The W3C box model, excludes the padding and border from the width/height
 of an element. A box having a width of 100px, with 2px padding on each 
side, a 3px border, and 7px margin on each side, will have a visible 
width of 124px.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;http://i1223.photobucket.com/albums/dd504/lloydom/box-model.gif&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;320&quot; src=&quot;http://i1223.photobucket.com/albums/dd504/lloydom/box-model.gif&quot; width=&quot;235&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In order to make IE use the W3C box model (which is what every other 
browser uses), your page needs to be rendered in Strict mode. By 
default, IE renders in Quirks mode.&lt;br /&gt;
&lt;br /&gt;
In order to trigger Strict mode in IE, you must specify a doctype. You can use any of the following doctypes:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
HTML4 Strict:&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;&lt;code&gt;&amp;lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.01//EN&quot;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;&quot;http://www.w3.org/TR/html4/strict.dtd&quot; &lt;/code&gt;&lt;code&gt;&amp;gt;&lt;/code&gt;
&lt;code&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
XHTML 1.0 Strict:&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;&lt;code&gt;&amp;lt;&lt;/code&gt;&lt;code&gt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Strict//EN&quot;
    &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd&quot;&amp;gt;

&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
XHTML 1.0 Transitional:&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;&lt;code&gt;&amp;lt;&lt;/code&gt;&lt;code&gt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot;
    &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&lt;/code&gt;&lt;code&gt;&amp;gt;&lt;/code&gt;
&lt;code&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
Your doctype must be the first thing to appear on your page. It is even before the  tag, on its own line. (Adding an  prolog will cause IE to go back in Quirks mode, so remove it if you have one).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://technicalwizardry.blogspot.com/feeds/4392422962147590678/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4930197226974329220/4392422962147590678' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4930197226974329220/posts/default/4392422962147590678'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4930197226974329220/posts/default/4392422962147590678'/><link rel='alternate' type='text/html' href='http://technicalwizardry.blogspot.com/2012/05/ie-box-model.html' title='IE BOX MODEL'/><author><name>lloyd</name><uri>http://www.blogger.com/profile/04794204354889644869</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgA5q0xlK7umtyyBWFkMQwZQOonP5LuVNL3QnnfiZ409SLryDamMSxGdyRR_LciyL1hZR4-DjkZSY7MmTEMdAChFXno-bc9lW3Lo5xV3dYQvdK11xedJ3oJG1_C6fxBgXE/s220/IMG_0236.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4930197226974329220.post-6612736339507314884</id><published>2012-05-31T06:59:00.000-07:00</published><updated>2013-04-03T00:29:14.364-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="technical"/><title type='text'>Event with jQuery.event.fix</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;h3&gt;



&lt;/h3&gt;
If you want to use the traditional HTML event binding and still use
 jQuery, here is a quick tip to get a “clean” (i.e. cross browsers) html
 event using jQuery.event.fix:&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;&lt;code&gt;

&amp;lt;input type=”file” name=”photoFile” onchange=”upload(event)”/&amp;gt;

&amp;lt;script&amp;gt;

function upload(e)
{

var e = $.event.fix(e);

alert(”target: ” + e.target);

}

&amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://technicalwizardry.blogspot.com/feeds/6612736339507314884/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4930197226974329220/6612736339507314884' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4930197226974329220/posts/default/6612736339507314884'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4930197226974329220/posts/default/6612736339507314884'/><link rel='alternate' type='text/html' href='http://technicalwizardry.blogspot.com/2012/05/event-with-jqueryeventfix.html' title='Event with jQuery.event.fix'/><author><name>lloyd</name><uri>http://www.blogger.com/profile/04794204354889644869</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgA5q0xlK7umtyyBWFkMQwZQOonP5LuVNL3QnnfiZ409SLryDamMSxGdyRR_LciyL1hZR4-DjkZSY7MmTEMdAChFXno-bc9lW3Lo5xV3dYQvdK11xedJ3oJG1_C6fxBgXE/s220/IMG_0236.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4930197226974329220.post-3658101158816883941</id><published>2012-05-31T00:07:00.001-07:00</published><updated>2013-04-03T00:29:14.358-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="technical"/><title type='text'>HTML 5 enabling your web application</title><content type='html'>&lt;div width=&quot;100%&quot;&gt;
There are several steps you need to take to ensure that your web application is ready for HTML 5. I am in the midst of a porting project from code that is
written specifically for IE 6 to make it HTML 5 enabled. Eventually this site should also be accessible on IPAD. I will list the steps to take and the things to watch out for. These are the steps and procedures that i am following.
&lt;/br&gt;&lt;/br&gt;
The first thing is to decide on the DOCTYPE. 
DOCTYPE is the document type in browsers, this was introduced so that browsers can support different version
of HTML. Setting  will ensure that the browser will run in the latest mode and that is HTML 5.
Setting a DOCTYPE like  means that browser will run in standard mode and is an HTML 4.01 version. There are several other doctypes that you can set,

This tells modern browsers that you want to display your HTML 4.01 page in strict compliance with the DTD. These browsers will go into &quot;strict&quot; or
&quot;standards&quot; mode and render the page in compliance with the standards. So for example in this case using  element will not work as it is not w3c
compliant.
&lt;/br&gt;
w3c is the governing body that defines the standards on HTML and what it does. When you set the DTD using the doctype it validates that the rendering is done as per the standard.&lt;/br&gt;&lt;/br&gt;
-----------------------------------&lt;/br&gt;
QUIRKS MODE&lt;/br&gt;
-----------------------------------&lt;/br&gt;
In IE, the rendering mode decides which box model it follows. In quirks mode it uses the traditional model, in strict mode the W3C model.

Doctype switching is the only way of selecting a box model in IE 6 Windows. Mozilla, Opera and IE Mac allow the use of the box-sizing declaration to select a box model, while Safari only supports the W3C box model.

See this site, it has more details:
http://www.quirksmode.org/css/quirksmode.html&lt;/br&gt;
-----------------------------------&lt;/br&gt;
Once you have set the doctype, make sure that the scripts , css are browser agnostic, now my current project the client has written code for IE 6 browser
and it is a 15 year old web application. To port something like this over here is a list of things to watch out for

1) window.event.keyCode is an IE only event property , to get it working on other browsers use
&lt;pre&gt;&lt;code&gt;
   if(window.event)
       keyPressed = window.event.keyCode; // IE
   else
       keyPressed = e.which; // Firefox
&lt;/code&gt;&lt;/pre&gt;
&lt;/br&gt;&lt;/br&gt;
2) window.event.srcElement works only on safari, chrome and IE. The window.event.srcElement equivalent in firefox is window.event.target.
&lt;pre&gt;&lt;code&gt;
   if (window.event) e = window.event;
          var srcElement = e.srcElement? e.srcElement : e.target;
&lt;/code&gt;&lt;/pre&gt;
&lt;/br&gt;&lt;/br&gt;
3) To get a custom attribute from an element, IE allows you to do something like this &lt;pre&gt;&lt;code&gt;window.event.srcElement.mycustomAttribute&lt;/code&gt;&lt;/pre&gt; , for a browser agnostic
version use &lt;pre&gt;&lt;code&gt;e.target.attributes[&quot;ibID&quot;].nodeValue&lt;/code&gt;&lt;/pre&gt;
&lt;/br&gt;&lt;/br&gt;
4) window.event.srcElement.innerText, innerText for a event srcElement works on chrome, IE and safar but on Firefox, you can use
window.event.srcElement.textContent
&lt;/br&gt;&lt;/br&gt;
5) window.event.srcElement.parentElement does not work on firefox, use parentNode which is the DOM equivalent and will work on all browsers
&lt;/br&gt;&lt;/br&gt;
6) IE will allow you to set custom attributes for elements for example: document.getElementById(&#39;mydiv&#39;).mycustomattr=55 , to get and set using DOM
properties use setAttribute and getAttribute.
&lt;/br&gt;&lt;/br&gt;
7) The biggest headache is using the document.all.name and document.all(id). This is an IE only property, it is not possible to just do a find and replace
on this because the document.all works as both a name and id selector. To explain this further if there is a function that does something like
&lt;pre&gt;&lt;code&gt;
function replacedoc(idsearch)
{
   var ele = document.all.idsearch;
   ......
   Look for a certain element
}&lt;/code&gt;&lt;/pre&gt;
&lt;/br&gt;&lt;/br&gt;
The above function will take an id for the element to search and look at the entire DOM. The document.all returns an array containing all the scripts and
elements. Now to port this over to cross browser, you will have to know what it is you are looking for and how it is represented in the DOM tree. &lt;/br&gt;
It is not that simple as you need to spend time to figure that out.
Using JQUERY here as an equivalent, you will have to know the following
&lt;/br&gt;
1. If a single element is fetched based on ID,&lt;/br&gt;&lt;/br&gt;
a) Use Jquery ID selector - ($(&#39;#id&#39;))&lt;/br&gt;
document.all.SideMenu can be replaced with $(&#39;#SideMenu&#39;)
Check for Null references before using it
&lt;/br&gt;&lt;/br&gt;
b) Use document.getElementById -
document.all.dlglst can be replaced with document.getElementById(&#39;dlglst&#39;)
&lt;/br&gt;&lt;/br&gt;
2. If a single the element is fetched based on name, use name selector.

&lt;/br&gt;&lt;/br&gt;
3. If it is of the form - &quot;document.all.&quot; + name; &lt;/br&gt;where name is a parameter passed - THis queries by both name and ID, use &quot;$(\&quot;[name=&#39;&quot; + name + &quot;&#39;], #&quot; + name + &quot;\&quot;)[0]&quot;

Note $(jquery object)[0] returns the HTML element alone. the variable enclosed by $ contains the entire jquery object.

&lt;/br&gt;&lt;/br&gt;

4. If multiple elements are fetched based on ID,
Document.all cannot be replaced with Jquery id selector in all scenarios because jquery id selector returns only the first element&lt;/br&gt;&lt;/br&gt;
http://api.jquery.com/id-selector/
- Each id value must be used only once within a document. If more than one element has been assigned the same ID, queries that use that ID will only select
the first matched element in the DOM. This behavior should not be relied on, however; a document with more than one element using the same ID is invalid&lt;/br&gt;
This happens if you have badly written HTML where multiple elements share the same ID and this very common in a lot of web applications.

&lt;/br&gt;&lt;/br&gt;
5) Onpropertychange is a IE specific event and the equivalent is DOMATTRModified which works on all browser. This however does not work as IE. In IE the
onpropertychange is fired if an element property including its attributes are modified by script.

&lt;/br&gt;&lt;/br&gt;
6) window.event.cancelBubble,&lt;/br&gt;

&lt;a href=&quot;http://msdn.microsoft.com/en-us/library/ms533545(v=vs.85).aspx&quot;&gt;http://msdn.microsoft.com/en-us/library/ms533545(v=vs.85).aspx&lt;/a&gt;&lt;/br&gt;

&lt;a href=&quot;http://javascript.about.com/od/byexample/a/events-cancelbubble-example.htm&quot;&gt;http://javascript.about.com/od/byexample/a/events-cancelbubble-example.htm&lt;/a&gt;&lt;/br&gt;

&lt;a href=&quot;http://www.quirksmode.org/js/events_order.html&quot;&gt;http://www.quirksmode.org/js/events_order.html&lt;/a&gt;&lt;/br&gt;

Call the event’s stopPropagation() method.
&lt;pre&gt;&lt;code&gt;
   function preventbubble(e)
   {
     if (e &amp;amp;&amp;amp; e.stopPropagation) //if stopPropagation method supported
        e.stopPropagation()
     else
        event.cancelBubble=true
   }
&lt;/code&gt;&lt;/pre&gt;
Use the jquery StopPropogation method
&lt;/br&gt;&lt;/br&gt;

7) document.body.parentElement.outerHTML , outerHTML is not supported on other browsers, use Jquery one for all browser
&lt;pre&gt;&lt;code&gt;  
var x = jQuery.extend(jQuery.Event(e.type), e).target.cloneNode(true);
alert($(x).wrap(&#39;&amp;lt;br /&amp;gt;&amp;lt;div&amp;gt;&amp;lt;/div&amp;gt;&#39;).parent().html());&quot;
&lt;/code&gt;&lt;/pre&gt;
&lt;/br&gt;&lt;/br&gt;

8) createElement, this is a DOM property but what it accepts as its function parameter should be kept in mind. Only IE will accept and element with the &amp;gt; and &amp;lt; tags.
&lt;pre&gt;&lt;code&gt;
      var oIFrame = document.createElement(&#39;&amp;lt;iframe class=&quot;doAsyncIFrameClass&quot; name=&quot; + szName + &quot;&amp;gt;&amp;amp;lt;p&amp;amp;gt;&#39;);
&lt;/code&gt;&lt;/pre&gt;
This should be replaced with

&lt;pre&gt;&lt;code&gt;
    var oIFrame = document.createElement(&#39;IFRAME&#39;)
    oIFrame.name = szName;
    oIFrame.Class = &#39;doAsyncIFrameClass&#39;; 
//(Note case-sensitivity &quot;Class&quot; and not &lt;/br&gt;&quot;class&quot; works on safari-mac)
    oIFrame.style.display = &#39;none&#39;;
&lt;/code&gt;&lt;/pre&gt;

&lt;/br&gt;&lt;/br&gt;
9) document.scripts works only on IE , use document.getElementsByTagName(&#39;script&#39;)

&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://technicalwizardry.blogspot.com/feeds/3658101158816883941/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/4930197226974329220/3658101158816883941' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4930197226974329220/posts/default/3658101158816883941'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4930197226974329220/posts/default/3658101158816883941'/><link rel='alternate' type='text/html' href='http://technicalwizardry.blogspot.com/2012/05/html-5-enabling-your-web-application.html' title='HTML 5 enabling your web application'/><author><name>lloyd</name><uri>http://www.blogger.com/profile/04794204354889644869</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgA5q0xlK7umtyyBWFkMQwZQOonP5LuVNL3QnnfiZ409SLryDamMSxGdyRR_LciyL1hZR4-DjkZSY7MmTEMdAChFXno-bc9lW3Lo5xV3dYQvdK11xedJ3oJG1_C6fxBgXE/s220/IMG_0236.jpg'/></author><thr:total>0</thr:total></entry></feed>