<?xml version="1.0" encoding="utf-8"?>
<feed xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xml:lang="en-us" xmlns="http://www.w3.org/2005/Atom">
  <title>kevin Mocha</title>
  <link rel="alternate" type="text/html" href="http://blog.ilovedoudou.com/" />
  <link rel="self" href="http://blog.ilovedoudou.com/SyndicationService.asmx/GetAtom" />
  <icon>favicon.ico</icon>
  <updated>2010-03-12T17:02:29.234917-05:00</updated>
  <author>
    <name>Kevin Mocha</name>
  </author>
  <subtitle>Bookmarks collected from web.</subtitle>
  <id>http://blog.ilovedoudou.com/</id>
  <generator uri="http://www.dasblog.net" version="1.9.6264.0">DasBlog</generator>
  <entry>
    <title>String format tricks</title>
    <link rel="alternate" type="text/html" href="http://blog.ilovedoudou.com/PermaLink,guid,0fd019c4-6afd-452e-a516-ef2314156e62.aspx" />
    <id>http://blog.ilovedoudou.com/PermaLink,guid,0fd019c4-6afd-452e-a516-ef2314156e62.aspx</id>
    <published>2010-03-12T17:02:29.234917-05:00</published>
    <updated>2010-03-12T17:02:29.234917-05:00</updated>
    <category term="DotNet" label="DotNet" scheme="http://blog.ilovedoudou.com/CategoryView,category,DotNet.aspx" />
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <br />
It is possible to set a minumum length e.g.<br />
string.format("{0,10:s}",12345"); will return a string 10 chars long with right alignment 
</p>
        <p>
string.format("{0,10:s}",12345"); will return a string 10 chars long with left alignment
</p>
        <img width="0" height="0" src="http://blog.ilovedoudou.com/aggbug.ashx?id=0fd019c4-6afd-452e-a516-ef2314156e62" />
      </div>
    </content>
  </entry>
  <entry>
    <title>Excerps from Programming Entity Framework</title>
    <link rel="alternate" type="text/html" href="http://blog.ilovedoudou.com/PermaLink,guid,d10d9b17-79fb-435c-bcdd-fcc3490c08be.aspx" />
    <id>http://blog.ilovedoudou.com/PermaLink,guid,d10d9b17-79fb-435c-bcdd-fcc3490c08be.aspx</id>
    <published>2010-03-10T15:25:05.5594065-05:00</published>
    <updated>2010-03-10T16:52:44.3959349-05:00</updated>
    <category term="DotNet" label="DotNet" scheme="http://blog.ilovedoudou.com/CategoryView,category,DotNet.aspx" />
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <a name="pose a">
          </a>Well-designed databases can pose a problem for developers.<a name="I_indexterm2_d1e1560"></a></p>
        <p>
          <a name="a database">
          </a>In the data world, a database is designed for maintainability,
security, efficiency, and scalability. Its data is organized in a way that satisfies
the demands of a good database administrator, yet provides challenges for the developer
who needs to access that data. 
</p>
        <p>
  
</p>
        <p>
The EDM follows this concept, but in the Entity Framework, it moves the modeling into
XML files that different programming models can use. The primary XML file contains
the <strong>conceptual model</strong>, which is the actual EDM. A second XML file
contains a <strong>representation of the database</strong> and a third, the <strong>mapping</strong> between
the first two. At design time, all three files are bundled into a single EDMX file.
The build process splits the EDMX out into the three metadata files that are used
at runtime. The Entity Framework then provides a framework that allows developers
to write .NET applications based on this model. 
</p>
        <p>
  
</p>
        <p>
          <a name="As long">
          </a>As long as the EDM provides the conceptual schema, a representation
of the database, a mapping file, and access to an Entity Framework-aware ADO.NET provider
for the target database, the Entity Framework doesn't care what database is being
targeted. It provides a common means of interacting with the database, common query
syntax, and a common method for sending changes back to the database.<a name="I_indexterm2_d1e1588"></a></p>
        <p>
          <a name="Framework provides">
          </a>Although the Entity Framework provides a very rich
set of features for developers, its most important capabilities are the following: 
</p>
        <ul>
          <li>
            <p>
              <a name="classes from">
              </a>It automatically generates classes from the model and updates
those classes dynamically anytime the model changes.
</p>
          </li>
          <li>
            <p>
              <a name="care of">
              </a>It takes care of all of the database connectivity so that developers
are not burdened by having to write lots of code for interacting with the database.
</p>
          </li>
          <li>
            <p>
              <a name="query syntax">
              </a>It provides common query syntax for querying the model,
not the database, and then translates these queries into queries that the database
can understand.
</p>
          </li>
          <li>
            <p>
              <a name="as they">
              </a>It provides a mechanism for tracking changes to the model's
objects as they are being used in applications, and handles the updates to the database.
</p>
          </li>
        </ul>
        <p>
          <a name="changes to">
          </a>In addition, because the model's classes are dynamically
generated, minor changes to the model need not have a major impact on your application.
Furthermore, modifying the model is much simpler than modifying your objects and the
data access code on which they rely. 
</p>
        <p>
  
</p>
        <p>
Navigation properties are pointers to related entities.<br />
An Entity Set<a name="for a"></a> is a container for a collection of entities of a
single type.<br /></p>
        <p>
          <a name="a&#xD;&#xA;        step">
          </a>Cleaning up the entity, property, and association names
is a step that you should consider performing immediately after you create a new model
with the ADO.NET Entity Data Model Wizard. In this way, as you begin to code against
the model, the names of the objects will be logical. Additionally, if you change these
names after you have begun to code, you will have to modify your code to reflect the
changes. 
</p>
        <p>
  
</p>
        <p>
The EDMX file is composed of two main sections: the runtime information and the Designer
information. The runtime section comprises three additional sections: one each for
storage models, conceptual models, and mappings. The Designer section specifies where
the various model elements should be placed visually in the Designer. 
</p>
        <p>
  
</p>
        <p>
          <a href="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/ExcerpsfromProgrammingEntityFramework_D949/image_2.png">
            <img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/ExcerpsfromProgrammingEntityFramework_D949/image_thumb.png" width="503" height="305" />
          </a>
        </p>
        <p>
  
</p>
        <p>
Why use the storage layer to represent the data store when you have the actual data
store to work with? There are a number of reasons to use this piece of the model.
The most important reason is that this provides loose coupling to the database; not
every object in the database needs to be in the mode 
</p>
        <p>
  
</p>
        <p>
Although the entire model is contained in a single file at design time, when the project
is compiled it will create three separate files—one for each of these sections. The
conceptual layer is saved to a file with a <i>.csdl</i><a name="storage layer"></a> extension,
which stands for Conceptual Schema Definition Language. The storage layer is saved
to a file with an <i>.ssdl</i><a name="Schema Definition"></a> extension (which stands
for Store Schema Definition Language) and the mapping layer is saved to a file with
an <i>.msl</i><a name="which is"></a> extension (which stands for Mapping Specification
Language). These files are used at runtime, which is why they are contained in a section
called <tt>edmx:Runtime</tt><a name="in the"></a> in the model. 
</p>
        <p>
  
</p>
        <p>
          <a href="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/ExcerpsfromProgrammingEntityFramework_D949/image_4.png">
            <img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/ExcerpsfromProgrammingEntityFramework_D949/image_thumb_1.png" width="603" height="296" />
          </a>
        </p>
        <p>
        </p>
        <p>
          <a name="container for">
          </a>Although it makes sense to have a container for an entity
because you could have many contact entities to work with, how would there be a collection
of associations? When you are working with entity objects, the associations between
the entities are also objects. If you have a single contact with multiple addresses
in memory, there would be one <tt>FK_Address_Contact</tt> association object for each
relationship. <a href="#two_association_objects_defining_relatio">Figure 2-14</a><a name="that are"></a> shows
two association objects that are used to define relationships between a single contact
and two addresses. 
</p>
        <p>
  
</p>
        <p>
&lt;NavigationProperty Name="Contact" 
</p>
        <p>
                     
Relationship="ProgrammingEFDB1Model.FK_Address_Contact" 
</p>
        <p>
                      
FromRole="Address" ToRole="Contact" /&gt; 
</p>
        <p>
  
</p>
        <p>
The collection that is exposed in the <tt>Addresses</tt><a name="not a"></a> navigation
property is not a collection from the <tt>System.Collections</tt> namespace, but rather
an <tt>EntityCollection</tt>. The <tt>EntityCollection</tt><a name="unique class"></a> is
a completely unique class in the Entity Framework. 
</p>
        <p>
  
</p>
        <p>
          <a href="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/ExcerpsfromProgrammingEntityFramework_D949/image_8.png">
            <img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/ExcerpsfromProgrammingEntityFramework_D949/image_thumb_3.png" width="673" height="645" />
          </a>
        </p>
        <p>
  
</p>
        <p>
          <a href="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/ExcerpsfromProgrammingEntityFramework_D949/image_6.png">
            <img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/ExcerpsfromProgrammingEntityFramework_D949/image_thumb_2.png" width="521" height="392" />
          </a>
        </p>
        <p>
        </p>
        <p>
The <tt>ReferentialConstraint</tt><a name="the&#xD;&#xA;        relationship"></a> element
serves a number of purposes. It specifies the direction of the relationship using
the Principal and Dependent role elements. In the example, <tt>Address</tt><a name="is dependent"></a> is
dependent upon <tt>Contact</tt><a name="to&#xD;&#xA;        defining"></a>. This also translates
to defining the primary key/foreign key relationship, and we finally see the foreign
key in the <tt>Address</tt><a name="the"></a> table identified: it is the <tt>ContactID</tt><a name="another piece"></a>.
This is another piece of the puzzle of how the association and the navigation property
work in the conceptual model. The <tt>ContactID</tt><a name="in the"></a> property
doesn't exist anywhere in the CSDL, but it is specified here in the SSDL. The MSL
will show us how they are linked.
</p>
        <p>
The last purpose of the <tt>ReferentialConstraint</tt> element is to stipulate that
a row in the <tt>Address</tt><a name="the"></a> table cannot exist without a reference
to a row in the <tt>People</tt><a name="of the"></a> table.
</p>
        <p>
If you check back at the CSDL's association in <a href="csdl_the_conceptual_schema.html#the_association_between_contact_and_addr">Example
2-2</a><a name="that this"></a>, you will see that this <tt>ReferentialConstraint</tt><a name="that constraint"></a> doesn't
exist. The CSDL enforces that constraint in a different way. The multiplicity for
the <tt>Person</tt><a name="in that"></a> entity type in that relationship is "1",
not "0..1".
</p>
        <p>
Designer's Mapping Details window
</p>
        <p>
          <a name="the">
          </a>Open the model in the XML Editor again and expand the <tt>&lt;edmx:Mappings&gt;</tt><a name="in how"></a> section;
you'll see that there is one big difference in how the mapping is described under
the covers. The mapping, as shown in <a href="#the_xml_view_of_the_contact_entity_mappi">Example
2-4</a><a name="the"></a>, is being made from the <tt>EntitySet</tt><a name="you may"></a>,
not the actual entity. When you add inherited types into the mix, you may also be
mapping <tt>Customer</tt><a name="s who"></a>s who are a type of <tt>Contact</tt><a name="the"></a>.
When you map the <tt>EntitySet</tt><a name="of the"></a> you cover all of the entity
types in an inheritance hierarchy. Therefore, the mapping needs to be done to the <tt>EntitySet</tt><a name="specific entity"></a>,
not a specific entity. 
</p>
        <p>
 
</p>
        <p>
          <a href="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/ExcerpsfromProgrammingEntityFramework_D949/image_10.png">
            <img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/ExcerpsfromProgrammingEntityFramework_D949/image_thumb_4.png" width="545" height="265" />
          </a>
        </p>
        <p>
          <a href="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/ExcerpsfromProgrammingEntityFramework_D949/image_12.png">
            <img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/ExcerpsfromProgrammingEntityFramework_D949/image_thumb_5.png" width="557" height="308" />
          </a>
        </p>
        <p>
          <a name="The Entity">
          </a>The Entity Framework automatically creates a set of classes
from the model. These classes are what you will work with when you query the model,
and objects will be returned that are based on these classes.<a name="I_indexterm2_d1e3773"></a><a name="I_indexterm2_d1e3778"></a><a name="I_indexterm2_d1e3783"></a></p>
        <p>
          <a name="change is">
          </a>Each time a change is made to the model and the model is then
saved, the Entity Framework's code generator kicks in and the classes are re-created. 
</p>
        <p>
  
</p>
        <p>
          <tt>
            <strong>
              <font color="#0000ff">IQueryable</font>
            </strong>
          </tt>
          <a name="LINQ query">
          </a> is
a LINQ query type. At design time, the compiler recognizes the LINQ query and does
its best to tell you its return type. The compiler doesn't realize that because it
is a LINQ to Entities<a name="it will"></a> query, it will be processed by the Entity
Framework and will result in an <tt>ObjectQuery</tt>. <font color="#0000ff"><tt>ObjectQuery</tt> implements <tt>IQueryable</tt></font><a name="are very"></a>,
so the two are very closely related. 
</p>
        <p>
        </p>
        <p>
          <tt>IQueryable</tt>
          <a name="the query">
          </a> contains metadata about the query, such
as the query expression and the provider being used. <tt>ObjectQuery</tt> is an <tt>IQueryable</tt><a name="query details"></a> with
additional query details that are specific to Entity Framework queries.
</p>
        <p>
The results are described as an "enumerable type," based on the class <tt>IEnumerable</tt>,
which is similar to a <tt>Collection</tt>. An <tt>IEnumerable</tt><a name="the collection"></a> allows
you to enumerate or iterate through each item in the collection as you did in the
preceding code sample (i.e., in <tt><a name="For Each"></a>For Each</tt>/<tt>foreach</tt>).
A <tt>Collection</tt> is an enhanced <tt>IEnumerable</tt>. Whereas an <tt>IEnumerable</tt><a name="familiar"></a> is
read-only, the more familiar <tt>Collection</tt><a name="to perform"></a> class allows
you to perform additional actions, such as adding or removing items from the group.
</p>
        <p>
          <strong>EntityClient</strong>: The Lowest-Level Method for Returning Streamed Data
Through EDM Queries
</p>
        <p>
//add new entities
</p>
        <div class="csharpcode">
          <a href="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/ExcerpsfromProgrammingEntityFramework_D949/image_18.png">
            <img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/ExcerpsfromProgrammingEntityFramework_D949/image_thumb_8.png" width="534" height="161" />
          </a>
        </div>
        <p>
//insert new parents and children
</p>
        <p>
          <a href="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/ExcerpsfromProgrammingEntityFramework_D949/image_16.png">
            <img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/ExcerpsfromProgrammingEntityFramework_D949/image_thumb_7.png" width="522" height="242" />
          </a>
        </p>
        <p>
          <a href="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/ExcerpsfromProgrammingEntityFramework_D949/image_14.png">
            <img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/ExcerpsfromProgrammingEntityFramework_D949/image_thumb_6.png" width="527" height="377" />
          </a>
        </p>
        <p>
          <a href="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/ExcerpsfromProgrammingEntityFramework_D949/image_20.png">
            <img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/ExcerpsfromProgrammingEntityFramework_D949/image_thumb_9.png" width="522" height="418" />
          </a>
        </p>
        <p>
          <a name="You can">
          </a>You can divide the core functionality of Object Services into
seven areas:<a name="I_indexterm9_d1e16964"></a></p>
        <ul>
          <li>
            <p>
Query processing
</p>
          </li>
          <li>
            <p>
Object materialization
</p>
          </li>
          <li>
            <p>
Object management
</p>
          </li>
          <li>
            <p>
Object relationship management
</p>
          </li>
          <li>
            <p>
Object state management
</p>
          </li>
          <li>
            <p>
              <a name="command processing">
              </a>Database Manipulation Language (DML) command processing
</p>
          </li>
          <li>
            <p>
Additional features
</p>
          </li>
        </ul>
        <p>
          <a name="high level">
          </a>At a high level, query processing in the Entity Framework
involves translating the LINQ or Entity SQL queries into queries that the data store
can process. At a lower level, it first parses your query into a command tree of LINQ
or Entity SQL query operators and functions, combined with the necessary entities
and properties of your model. The command tree is a format that the various providers
that have been designed to work with the Entity Framework will be expecting. Next,
the provider API (Oracle, SQL Server, MySQL, etc.) transforms this tree into a new
expression tree composed of the provider's operators and functions and the database's
tables and columns. This tree is finally passed to the database.<a name="I_indexterm9_d1e17014"></a><a name="I_indexterm9_d1e17017"></a></p>
        <p>
        </p>
        <p>
        </p>
        <p>
        </p>
        <p>
          <a name="LINQ starts">
          </a>LINQ starts its journey in the LINQ APIs and is then passed
to the Object Services API. When you create a LINQ to Entities query, you are using
syntax that is built into Visual Basic and C# that has enhancements that the Entity
Framework has added. LINQ converts this query into a LINQ expression tree, which deconstructs
the query into its common operators and functions. The LINQ expression tree is then
passed to Object Services, which converts the expression tree to a command tree. 
</p>
        <p>
  
</p>
        <p>
          <a href="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/ExcerpsfromProgrammingEntityFramework_D949/image_22.png">
            <img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/ExcerpsfromProgrammingEntityFramework_D949/image_thumb_10.png" width="508" height="363" />
          </a>
        </p>
        <p>
 
</p>
        <p>
          <a name="I_indexterm9_d1e17056">
          </a>
          <strong>
            <font color="#0000ff">Customizing Entity
Data Models</font>
          </strong>
        </p>
        <p>
In object-oriented programming, when one object is a type of another object, you can
use inheritance to share properties so that the properties of a base type (e.g., <tt>Contact</tt>)
are exposed directly in a derived type (e.g., <tt>Customer</tt><a name="allow"></a>).
The EDM supports inheritance as well. The inheritance mapping used to allow <tt>Customer</tt> to
derive from <tt>Contact</tt> and absorb <tt>Contact</tt>'s properties is called <strong>Table
per Type inheritance</strong><a name="to simplify"></a>. Let's investigate this one
first, and modify the model to simplify working with customers.<a name="I_indexterm9_d1e17066"></a></p>
        <p>
          <strong>Entity splitting</strong>, also referred to as vertical splitting<a name="map a"></a>,
allows you to map a single entity to more than one table. You can use entity splitting
when tables share a common key; for example, if a contact's personal and business
information is stored in separate tables. You can use entity splitting as long as
the primary keys in the two database tables match.<br />
(Entity splitting can solve this problem very easily, by mapping both the <tt>Customer</tt> table
and the <tt>ContactPersonalInfo</tt> table to the <tt>Customer</tt> entity.)
</p>
        <p>
          <strong>Conditional mapping</strong> places a permanent filter on an entity by defining
that an entity will be mapped to data in the database under only certain conditions.
</p>
        <p>
          <a name="Another type">
          </a>Another type of inheritance that the EDM supports is <strong>Table
per Hierarchy (TPH).</strong> TPH inheritance depends on conditional mapping. Rather
than including only records that match the condition, the condition is used to define
records as different types. 
</p>
        <p>
  
</p>
        <p>
          <strong>Creating Complex Types to Encapsulate Sets of Properties</strong>
        </p>
        <p>
          <strong>
          </strong>  
</p>
        <p>
          <tt>
            <strong>
              <font size="2">QueryView</font>
            </strong>
          </tt>
          <a name="is a">
          </a> is a
mapping that allows you to override the default mapping for an entity set and return
read-only data. <tt>QueryView</tt><a name="need to"></a> is something you need to
enter manually in the XML, and it belongs in the mapping layer. <a name="ch12_QueryView"></a><a name="ch12_EDMcustomQV"></a><a name="ch12_mappingsQV"></a></p>
        <p>
A <tt>QueryView</tt><a name="that is"></a> is a query that is expressed using Entity
SQL syntax. However, rather than creating the Entity SQL expression against the conceptual
layer of the model, the target of the expression is the store (SSDL) layer. In other
words, when you construct the Entity SQL for a <tt>QueryView</tt><a name="is written"></a>,
the query is written against the elements of the SSDL.<br /></p>
        <p>
Although <tt>QueryView</tt> returns read-only entities, if you want to use <tt>QueryView</tt><a name="to be"></a> for
some of its other benefits, you can force the entity to be updatable. Entities that
are mapped with <tt>QueryView</tt> are still change-tracked by the <tt>ObjectContext</tt><a name="automatically generate"></a>.
However, the Entity Framework is not able to automatically generate <tt>Insert</tt>, <tt>Update</tt>,
and <tt>Delete</tt><a name="can always"></a> commands for these entities. Instead,
you can always create function mappings, as you did for the <tt>Payment</tt> entity.
Then the entity that came from a <tt>QueryView</tt> will be affected by the call to <tt>SaveChanges</tt>.<br /></p>
        <p>
In addition to returning read-only entities, another benefit of <tt>QueryView</tt><a name="you saw"></a> is
that you can overcome the limitations of conditional mapping. As you saw earlier,
conditional mapping lets you filter using <tt>=</tt>, <tt><a name="Is Null"></a>Is
Null</tt>, and <tt>Is Not Null</tt>. 
<br />
Using a <tt>QueryView</tt><a name="with a"></a><strong>you can filter with a much
wider variety of operators</strong>, including <tt>&gt;</tt> and <tt>&lt;</tt>. However,
because <tt>QueryView</tt><a name="need the"></a> returns read-only data, if you need
the entity that results to be updatable, you can still achieve this by mapping stored
procedures to the entity that results.
</p>
        <img width="0" height="0" src="http://blog.ilovedoudou.com/aggbug.ashx?id=d10d9b17-79fb-435c-bcdd-fcc3490c08be" />
      </div>
    </content>
  </entry>
  <entry>
    <title>WCF Overview</title>
    <link rel="alternate" type="text/html" href="http://blog.ilovedoudou.com/PermaLink,guid,2e9d170a-7f75-410a-ba30-9d85e800ad61.aspx" />
    <id>http://blog.ilovedoudou.com/PermaLink,guid,2e9d170a-7f75-410a-ba30-9d85e800ad61.aspx</id>
    <published>2010-03-09T15:17:35.125272-05:00</published>
    <updated>2010-03-10T11:11:38.1677341-05:00</updated>
    <category term="DotNet" label="DotNet" scheme="http://blog.ilovedoudou.com/CategoryView,category,DotNet.aspx" />
    <category term="Life / Career" label="Life / Career" scheme="http://blog.ilovedoudou.com/CategoryView,category,Life%2B%2c%2BCareer.aspx" />
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <a title="http://www.codeproject.com/KB/webservices/Programming_WCF.aspx" href="http://www.codeproject.com/KB/webservices/Programming_WCF.aspx">http://www.codeproject.com/KB/webservices/Programming_WCF.aspx</a>
        </p>
        <p>
The WCF programming model unifies <a href="http://en.wikipedia.org/wiki/Web_Services">Web
Services</a>, <a href="http://en.wikipedia.org/wiki/.NET_Remoting">.NET Remoting</a>, <a href="http://en.wikipedia.org/wiki/Microsoft_Transaction_Server">Distributed
Transactions</a>, and <a href="http://en.wikipedia.org/wiki/Microsoft_Message_Queuing">Message
Queues</a> into a single <a href="http://en.wikipedia.org/wiki/Service-oriented_architecture">Service-oriented
programming</a> model for <a href="http://en.wikipedia.org/wiki/Distributed_computing">distributed
computing</a>. WCF uses <a href="http://en.wikipedia.org/wiki/SOAP">SOAP</a> messages
for communication between two processes, thereby making WCF-based applications interoperable
with any other process that communicates via SOAP messages.
</p>
        <p>
A WCF Service is composed of three components parts viz, 
</p>
        <p>
1) <strong>Service Class -</strong> A WCF service class implements some service as
a set of methods. 
</p>
        <p>
2) <strong>Host Environment</strong> - A Host environment can be a Console application
or a Windows Service or a Windows Forms application or IIS as in case of the normal
asmx web service in .NET. 
</p>
        <p>
3) <strong>Endpoints</strong> - All communications with the WCF service will happen
via the endpoints. The endpoint is composed of 3 parts (collectively called as ABC's
of endpoint) as defines below: 
</p>
        <p>
          <strong>Address: </strong>The endpoints specify a Address that defines where the endpoint
is hosted. 
</p>
        <p>
          <strong>Contract: </strong>The endpoints specify a Contract that defines which methods
of the Service class will be accessible via the endpoint; each endpoint may expose
a different set of methods. 
</p>
        <p>
          <strong>Binding: </strong>The endpoints also define a binding that specifies how a
client will communicate with the service and the address where the endpoint is hosted.Various
components of the WCF are depicted in the figure below. 
</p>
        <p>
          <img alt="Screenshot - WCF_Arch.gif" src="http://www.codeproject.com/KB/webservices/Programming_WCF/WCF_Arch.gif" width="398" height="164" />
        </p>
        <p>
Who How What
</p>
        <p>
There are three types of contracts namely,
</p>
        <p>
          <strong>Service Contracts - </strong>Describes the operations a service can perform.
Maps CLR types to WSDL.<br /><strong>Data Contracts</strong> - Describes a data structure. Maps CLR types to XSD.<br /><strong>Messaga Contracts - </strong>Defines the structure of the message on the wire.
Maps CLR types to SOAP messages.
</p>
        <p>
Bindings can be defined in config file as well as programattically.
</p>
        <p>
Services have behaviors that control their concurrency, throttling, transactions,<br />
security, and other system semantics. 
</p>
        <p>
  
</p>
        <p>
Metadata in WCF refers to the information that describes precisely how to<br />
communicate with a service. Clients can request metadata from a running<br />
service to learn about their endpoints and the message formats that they 
</p>
        <p>
require. At design time, clients send a request message defined by the<br />
WS-MetadataExchange standard and receive WSDL in return. The WSDL<br />
can be used by the client to define a proxy class and configuration file that<br />
will later be used at runtime to communicate with the service. Figure 1.4<br />
shows this interaction. 
</p>
        <p>
          <a href="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/WCFOverview_D799/image_2.png">
            <img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/WCFOverview_D799/image_thumb.png" width="424" height="205" />
          </a>
        </p>
        <p>
Use svcutil.exe to generate the proxy code
</p>
        <img width="0" height="0" src="http://blog.ilovedoudou.com/aggbug.ashx?id=2e9d170a-7f75-410a-ba30-9d85e800ad61" />
      </div>
    </content>
  </entry>
  <entry>
    <title>Component-Oriented Programming</title>
    <link rel="alternate" type="text/html" href="http://blog.ilovedoudou.com/PermaLink,guid,bc74545d-dbbc-4b34-bfd8-238e1e472dff.aspx" />
    <id>http://blog.ilovedoudou.com/PermaLink,guid,bc74545d-dbbc-4b34-bfd8-238e1e472dff.aspx</id>
    <published>2010-03-09T14:22:24.9700782-05:00</published>
    <updated>2010-03-09T14:25:48.4349216-05:00</updated>
    <category term="Design" label="Design" scheme="http://blog.ilovedoudou.com/CategoryView,category,Design.aspx" />
    <category term="Life / Career" label="Life / Career" scheme="http://blog.ilovedoudou.com/CategoryView,category,Life%2B%2c%2BCareer.aspx" />
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <a title="http://en.wikipedia.org/wiki/Component-oriented_programming" href="http://en.wikipedia.org/wiki/Component-oriented_programming">http://en.wikipedia.org/wiki/Component-oriented_programming</a>
        </p>
        <p>
The main idea is <i>separation of concerns</i>;
</p>
        <p>
Software engineers regard components as part of the starting platform for service
orientation. Components play this role, for example, in <a href="http://en.wikipedia.org/wiki/Web_Services">Web
Services</a>, and more recently, in <a href="http://en.wikipedia.org/wiki/Service-oriented_architecture">Service-Oriented
Architecture (SOA)</a> - whereby a component is converted<sup>[<i><a href="http://en.wikipedia.org/wiki/Wikipedia:Avoid_weasel_words">by
whom?</a></i>]</sup> into a <i>service</i> and subsequently inherits further characteristics
beyond that of an ordinary component.
</p>
        <p>
An individual component is a software package or a <a href="http://en.wikipedia.org/wiki/Modular_programming">module</a> that
encapsulates a set of related functions (or data).
</p>
        <p>
All system processes are placed into separate components so that all of the data and
functions inside each component are semantically related (just as with the contents
of classes). Because of this principle, it is often said that components are <i>modular</i> and <i>cohesive</i>.
</p>
        <p>
With regard to system-wide co-ordination, components communicate with each other <strong>via <i>interfaces</i></strong>.
When a component offers services to the rest of the system, it adopts a <i>provided</i> interface
which specifies the services that can be utilized by other components and how. This
interface can be seen as a <strong>signature</strong> of the component - the client
does not need to know about the inner workings of the component (implementation) in
order to make use of it. This principle results in components referred to as <i><strong><font color="#ff0000">encapsulated</font></strong></i>.
</p>
        <p>
Another important attribute of components is that they are <i><strong><font color="#ff0000">substitutable</font></strong></i>,
</p>
        <p>
Software components often take <strong>the form of </strong><a href="http://en.wikipedia.org/wiki/Object_%28computing%29"><strong>objects</strong></a><strong> or
collections of objects</strong> (from <a href="http://en.wikipedia.org/wiki/Object-oriented_programming">object-oriented
programming</a>), in some binary or textual form, adhering to some <a href="http://en.wikipedia.org/wiki/Interface_description_language">interface
description language</a> (IDL) so that the component may exist autonomously from other
components in a <a href="http://en.wikipedia.org/wiki/Computer">computer</a>.
</p>
        <p>
          <a href="http://en.wikipedia.org/wiki/Reusability">
            <strong>
              <font color="#ff0000">Reusability</font>
            </strong>
          </a> is
an important characteristic of a high-quality software component. A software component
should be designed and implemented so that it can be reused in many different programs. 
</p>
        <p>
It takes significant effort and awareness to write a software component that is effectively
reusable. The component needs to be: 
</p>
        <ul>
          <li>
fully documented 
</li>
          <li>
thoroughly tested 
<ul><li>
robust - with comprehensive input-validity checking 
</li><li>
able to pass back appropriate <a href="http://en.wikipedia.org/wiki/Error_message">error
messages</a> or return codes 
</li></ul></li>
          <li>
designed with an awareness that it <i>will</i> be put to unforeseen uses 
</li>
        </ul>
        <h4>Differences from object-oriented programming
</h4>
        <p>
Proponents of <a href="http://en.wikipedia.org/wiki/Object-oriented_programming">object-oriented
programming</a> (OOP) maintain that software should be written according to a mental
model of the actual or imagined objects it represents. OOP and the related disciplines
of <a href="http://en.wikipedia.org/wiki/Object-oriented_design">object-oriented design</a> and <a href="http://en.wikipedia.org/wiki/Object-oriented_analysis">object-oriented
analysis</a> focus on modeling real-world<sup>[<i><a href="http://en.wikipedia.org/wiki/Wikipedia:Citation_needed">citation
needed</a></i>]</sup> interactions and attempting to create "verbs" and "nouns" which
can be used in intuitive<sup>[<i><a href="http://en.wikipedia.org/wiki/Wikipedia:Citation_needed">citation
needed</a></i>]</sup> ways, ideally by end users as well as by programmers coding
for those end users. 
</p>
        <p>
Component-based software engineering, by contrast, makes no such assumptions, and
instead states that developers should construct software by gluing together prefabricated
components - much like in the fields of <a href="http://en.wikipedia.org/wiki/Electronics">electronics</a> or <a href="http://en.wikipedia.org/wiki/Mechanics">mechanics</a>.
Some peers<sup>[<i><a href="http://en.wikipedia.org/wiki/Wikipedia:Avoid_weasel_words">who?</a></i>]</sup> will
even talk of modularizing systems as software components as a new <a href="http://en.wikipedia.org/wiki/Programming_paradigm">programming
paradigm</a>. 
</p>
        <p>
  
</p>
        <p>
  
</p>
        <p>
  
</p>
        <p>
          <em>
            <strong>
              <font color="#0080ff">Component-based development (CBD) is an extension
of object-oriented programming. CBD does away with the language and vendor-specific
limitations of OOP, and makes software reuse more practical and accelerates the development
process. Event-based programming is the next logical step in CBD, and makes components
more reusable due to their decoupled nature. But event-based systems are easier to
develop, which means they are cheaper and more reliable than traditional OOP or CBD
systems.</font>
            </strong>
          </em>
          <img width="0" height="0" src="http://blog.ilovedoudou.com/aggbug.ashx?id=bc74545d-dbbc-4b34-bfd8-238e1e472dff" />
        </p>
      </div>
    </content>
  </entry>
  <entry>
    <title>Web 2.0 Security (part 1)</title>
    <link rel="alternate" type="text/html" href="http://blog.ilovedoudou.com/PermaLink,guid,2f2a66c4-a599-4a92-bfa1-7f859162fb34.aspx" />
    <id>http://blog.ilovedoudou.com/PermaLink,guid,2f2a66c4-a599-4a92-bfa1-7f859162fb34.aspx</id>
    <published>2010-03-07T00:08:42.6721435-05:00</published>
    <updated>2010-03-07T00:08:42.6721435-05:00</updated>
    <category term="Life / Career" label="Life / Career" scheme="http://blog.ilovedoudou.com/CategoryView,category,Life%2B%2c%2BCareer.aspx" />
    <category term="Web" label="Web" scheme="http://blog.ilovedoudou.com/CategoryView,category,Web.aspx" />
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
Web 2.0 addresses the new web technologies that are used to bring more <strong>interactivity</strong> to
web<br />
applications. 
</p>
        <p>
Additionally, Web 2.0 also includes a behavioral shift on the web, where users are<br />
encouraged to customize their own content on web applications rather than view static/<br />
generic content supplied by an organization.
</p>
        <p>
In addition to the technology and behavior changes, Web 2.0 can also mean the shift<br />
from shrink-wrapped software to software as a service. 
</p>
        <p>
  
</p>
        <p>
Another aspect of Web 2.0 are mash-up and plug-in pages. (Personal google page) 
</p>
        <p>
  
</p>
        <p>
Injection attacks are based on a single problem that persists in many technologies:
namely,<br />
no strict separation exists between program instructions and user data (also referred
to as<br />
user input). This problem allows for attackers to sneak program instructions into
places<br />
where the developer expected only benign data. By sneaking in program instructions,
the<br />
attacker can instruct the program to perform actions of the attacker’s choosing. 
</p>
        <p>
  
</p>
        <p>
          <strong>
            <font color="#0000ff" size="3">Input Injection</font>
          </strong>
        </p>
        <p>
          <strong>
          </strong>  
</p>
        <p>
          <strong>SQL Injection</strong>
        </p>
        <p>
  
</p>
        <p>
SELECT id FROM user_table WHERE username = '' <font color="#ff0000">OR 1=1 -- </font>'
AND password<br />
= PASSWORD('x') 
</p>
        <p>
  
</p>
        <p>
Injection attacks are not necessary blind attacks. Many web applications are developed<br />
with open-source tools. To make injection attacks more successful, download free or<br />
evaluation copies of products and set up your own test system. Once you have found
an<br />
error in your test system, it is highly probable that the same issue will exist on
all web<br />
applications using that tool. 
</p>
        <p>
  
</p>
        <p>
Cure: 1. constrain data types, escape user input, prepared statements (the best) 
</p>
        <p>
  
</p>
        <p>
          <strong>XPath Injection</strong>
        </p>
        <p>
//users[username/text()='admin' and password/text()='' or '1'='1' ]/id/text() 
</p>
        <p>
  
</p>
        <p>
          <strong>Command Injection </strong>(Escape) 
</p>
        <p>
          <strong>Directory Transversal Attacks<br />
XXE (XML eXternal Entity) Attacks </strong>(prohibit the external entity in XML parser) 
</p>
        <p>
          <strong>LDAP Injection<br /></strong>whitelisting characters—that is, allow<br />
alphanumeric characters (a–z, A–Z, and 0–9) and deny all other characters.<br /><strong>Buffer Overflows</strong><br />
The injection aspect of buffer overflows is that the attacker injects<br />
machine instructions (called shell code) into some user input. The attacker somewhat
needs to<br />
know where the shell code will end up in the memory of the computer running the web<br />
application. Then the attacker overwrites the return address to point to the memory
location<br />
of the shell code. <img width="0" height="0" src="http://blog.ilovedoudou.com/aggbug.ashx?id=2f2a66c4-a599-4a92-bfa1-7f859162fb34" /></p>
      </div>
    </content>
  </entry>
  <entry>
    <title>Summary of HTTP Developer&amp;rsquo;s Handbook (part 3)</title>
    <link rel="alternate" type="text/html" href="http://blog.ilovedoudou.com/PermaLink,guid,96b414d4-7024-4eaf-b68d-d3239f7f8a8a.aspx" />
    <id>http://blog.ilovedoudou.com/PermaLink,guid,96b414d4-7024-4eaf-b68d-d3239f7f8a8a.aspx</id>
    <published>2010-03-06T20:06:37.7635271-05:00</published>
    <updated>2010-03-06T20:06:57.4662738-05:00</updated>
    <category term="Life / Career" label="Life / Career" scheme="http://blog.ilovedoudou.com/CategoryView,category,Life%2B%2c%2BCareer.aspx" />
    <category term="Web" label="Web" scheme="http://blog.ilovedoudou.com/CategoryView,category,Web.aspx" />
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <font color="#0000ff" size="2">
            <strong>                                              
Security</strong>
          </font>
        </p>
        <p>
HTTP offers integrated mechanisms for authenticating users. Collectively referred
to as HTTP authentication, these mechanisms provide a way for users to be authenticated
without the necessity of any server-side programming logic. This can be especially
helpful for restricting access to static resources (such as images or HTML files).
Of course, server-side scripts can also implement HTTP authentication, although Web
developers often authenticate users in the application logic itself. 
</p>
        <p>
There are two basic types of HTTP authentication: 
</p>
        <ul>
          <li>
            <p>
Basic authentication<a name="idd1e25584"></a><a name="idd1e25589"></a><a name="idd1e25594"></a></p>
          </li>
          <li>
            <p>
Digest authentication
</p>
          </li>
        </ul>
        <p>
          <a href="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/SummaryofHTTPDevelopersHandbookpart3_11AB8/image_2.png">
            <img style="border-bottom: 0px; border-left: 0px; display: inline; margin-left: 0px; border-top: 0px; margin-right: 0px; border-right: 0px" title="image" border="0" alt="image" align="left" src="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/SummaryofHTTPDevelopersHandbookpart3_11AB8/image_thumb.png" width="395" height="153" />
          </a>
          <a name="idd1e25602">
          </a>
          <a name="idd1e25607">
          </a>
          <a name="idd1e25612">
          </a>
        </p>
        <p>
          <a href="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/SummaryofHTTPDevelopersHandbookpart3_11AB8/image_4.png">
            <img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/SummaryofHTTPDevelopersHandbookpart3_11AB8/image_thumb_1.png" width="434" height="153" />
          </a>
        </p>
        <p>
An elegant solution to these types of problems is SSL, Secure Sockets Layer. In 1994,
Netscape released the specification of Secure Sockets Layer. By 1995, version 3.0
of SSL was released, and it has since taken the Web by storm. SSL has dramatically
changed the way people use the Web, and it provides a very good solution to many of
the Web's shortcomings, most importantly: 
</p>
        <ul>
          <li>
            <p>
Data integrity— SSL can <a name="idd1e27328"></a><a name="idd1e27333"></a>help ensure
that data (HTTP messages) cannot be changed while in transit.
</p>
          </li>
          <li>
            <p>
Data confidentiality— SSL<a name="idd1e27351"></a><a name="idd1e27356"></a> provides
strong cryptographic techniques used to encrypt HTTP messages.
</p>
          </li>
          <li>
            <p>
Identification— SSL can<a name="idd1e27374"></a><a name="idd1e27379"></a> offer reasonable
assurance as to the identity of a Web server. It can also be used to validate the
identity of a client, but this is less common.
</p>
          </li>
        </ul>
        <p>
A digital certificate is a document that declares that a particular public key is
owned by a particular Web site (see <a href="#ch18fig003">Figure 18.3</a>). The CA's
role is very similar to a notary whose responsibility is to ensure the correct identity
of people signing a legal document. 
</p>
        <p>
  
</p>
        <p>
SSL is basically a protocol<a name="idd1e27890"></a><a name="idd1e27895"></a> that
employs both symmetric and asymmetric cryptography to protect messages that use TCP
as the transport-level protocol. Because of the high performance expense of asymmetric
cryptography, it is only used to exchange the randomly generated symmetric key that
is then used for the symmetric encryption of the HTTP messages. 
</p>
        <p>
  
</p>
        <p>
          <a href="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/SummaryofHTTPDevelopersHandbookpart3_11AB8/image_6.png">
            <img style="border-bottom: 0px; border-left: 0px; margin: 0px 20px 0px 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" align="left" src="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/SummaryofHTTPDevelopersHandbookpart3_11AB8/image_thumb_2.png" width="299" height="137" />
          </a>
        </p>
        <p>
          <a href="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/SummaryofHTTPDevelopersHandbookpart3_11AB8/image_8.png">
            <img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/SummaryofHTTPDevelopersHandbookpart3_11AB8/image_thumb_3.png" width="425" height="253" />
          </a> https
on port 443
</p>
        <p>
Whenever a Web browser connects to a Web site over a secure connection, it requires
that the SSL certificate<a name="idd1e27937"></a><a name="idd1e27942"></a> the Web
server presents meets three main conditions:
</p>
        <ul>
          <li>
            <p>
The domain name on the certificate must match the domain name the Web browser believes
itself to be requesting a resource from.
</p>
          </li>
          <li>
            <p>
The certificate must be valid (not expired).
</p>
          </li>
          <li>
            <p>
The certificate must be signed by a trusted certificate authority (CA).
</p>
          </li>
        </ul>
        <p>
Transport Layer Security (TLS) <a name="idd1e28483"></a><a name="idd1e28489"></a><a name="idd1e28494"></a>is
a formally standardized version of SSL. The biggest difference, in fact, is that TLS
is defined and maintained by an international standards body, the Internet Engineering
Task Force (IETF). <a name="idd1e28498"></a><a name="idd1e28504"></a><a name="idd1e28509"></a><a name="idd1e28512"></a>SSL
is developed and maintained by Netscape. 
</p>
        <p>
  
</p>
        <p>
One of the advantages of the IETF's involvement in TLS is that they also control the
HTTP protocol. <a name="idd1e28528"></a><a name="idd1e28535"></a><a name="idd1e28542"></a><a name="idd1e28547"></a>This
situation can possibly be credited for RFC 2817, which describes a method for using
the <tt>Upgrade</tt> general header to upgrade to HTTP over TLS. The significance
of this is that it allows for a change in protocol without having to utilize a separate
port. Thus, a Web server that supports this technique can implement TLS over port
80. An example of a Web client's request is the following:
</p>
        <pre>GET / HTTP/1.1 
Host: 127.0.0.1 
Upgrade: TLS/1.0 
Connection: Upgrade </pre>
        <p>
A Web server that accepts this upgrade will issue an HTTP response similar to the
following:
</p>
        <pre>HTTP/1.1 101 Switching Protocols 
Upgrade: TLS/1.0, HTTP/1.1 
Connection: Upgrade </pre>
        <p>
At this point, a typical SSL handshake<a name="idd1e28574"></a><a name="idd1e28577"></a> will
take place over the current connection. It is sometimes confusing to consider that
the SSL handshake can take place over port 80 at this point while the Web server can
still accept normal HTTP requests over the same port. Note that the upgrade only affects
the current TCP connection. Just as a Web server does not (barring extremely odd memory
collisions) send the wrong HTTP response to the wrong Web client, it can also keep
protocol upgrades straight. <img width="0" height="0" src="http://blog.ilovedoudou.com/aggbug.ashx?id=96b414d4-7024-4eaf-b68d-d3239f7f8a8a" /></p>
      </div>
    </content>
  </entry>
  <entry>
    <title>Summary of HTTP Developer&amp;rsquo;s Handbook (part 3)</title>
    <link rel="alternate" type="text/html" href="http://blog.ilovedoudou.com/PermaLink,guid,205ad14d-1123-4af7-9e85-7c02b4eb649a.aspx" />
    <id>http://blog.ilovedoudou.com/PermaLink,guid,205ad14d-1123-4af7-9e85-7c02b4eb649a.aspx</id>
    <published>2010-03-06T15:56:19.47846-05:00</published>
    <updated>2010-03-06T15:56:19.47846-05:00</updated>
    <category term="Life / Career" label="Life / Career" scheme="http://blog.ilovedoudou.com/CategoryView,category,Life%2B%2c%2BCareer.aspx" />
    <category term="Web" label="Web" scheme="http://blog.ilovedoudou.com/CategoryView,category,Web.aspx" />
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <strong>
            <font color="#0000ff" size="2">Maintaining State</font>
          </strong>
        </p>
        <p>
If a unique response per client is desired, something in the HTTP request itself must
be unique.
</p>
        <p>
Once a method of state management has been established, you need only to authenticate
the user once. <a name="idd1e20028"></a>Because state management provides a way to
identify a Web client, user identification simply requires that you remember which
user is associated with which client upon authentication. 
</p>
        <p>
          <a href="0672324547_">
            <img border="0" src="FILES/pixel.gif" width="1" height="1" />
          </a>
        </p>
        <p>
When I speak of maintaining state,<a name="idd1e20042"></a><a name="idd1e20047"></a><a name="idd1e20050"></a> I
am only speaking of client identification, which is accomplished by associating <strong>multiple</strong> HTTP
requests. 
</p>
        <p>
Maintaining session, <a name="idd1e20057"></a>on the other hand, requires two related
tasks: 
</p>
        <ul>
          <li>
            <p>
Identifying the client (state management)
</p>
          </li>
          <li>
            <p>
Retaining information about the client
</p>
          </li>
        </ul>
        <p>
Although cookies are most often described in conversation as if they are entities
(for example, "a Web server sends you a cookie"), they are much easier to understand
at a functional level if you consider them an extension of the HTTP protocol, which
is actually more correct. Cookies can be defined as the addition of two HTTP headers<a name="idd1e20166"></a><a name="idd1e20173"></a><a name="idd1e20176"></a><a name="idd1e20181"></a><a name="idd1e20188"></a><a name="idd1e20191"></a>: 
</p>
        <ul>
          <li>
            <p>
              <tt>Set-Cookie</tt> response header
</p>
          </li>
          <li>
            <p>
              <tt>Cookie</tt> request header
</p>
          </li>
        </ul>
        <p>
          <a href="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/SummaryofHTTPDevelopersHandbookpart3_E00E/image_2.png">
            <img style="border-bottom: 0px; border-left: 0px; margin: 0px 20px 0px 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" align="left" src="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/SummaryofHTTPDevelopersHandbookpart3_E00E/image_thumb.png" width="375" height="449" />
          </a>
        </p>
        <p>
    A common question seen on mailing lists and discussion forums for
Web developers is how to test whether the client is accepting cookies, and many people
do not understand the answer. As is evident in <a href="#ch11fig003">Figure 11.3</a>,
it is impossible to determine whether the client accepted the cookie until the second
request is sent (step 3 in the figure). If the cookie is included in the second request,
the client accepted it. If not, the client rejected it.
</p>
        <p>
Some developers choose to force the issue of determining whether the client accepts
cookies by redirecting the client to a second URL upon entrance.
</p>
        <p>
Cookies have become a source of<a name="idd1e20678"></a><a name="idd1e20683"></a><a name="idd1e20688"></a><a name="idd1e20693"></a> privacy
concern in recent years. As with most technologies in the computer industry, this
reputation has been earned by the misuse of the technology more than the technology
itself.
</p>
        <p>
Whether using files or a database to store the session information, there are three
basic elements you will want to store for each session's record:
</p>
        <ul>
          <li>
            <p>
Unique identifier
</p>
          </li>
          <li>
            <p>
Timestamp of last access
</p>
          </li>
          <li>
            <p>
Client data
</p>
          </li>
        </ul>
        <p>
          <a href="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/SummaryofHTTPDevelopersHandbookpart3_E00E/image_4.png">
            <img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/SummaryofHTTPDevelopersHandbookpart3_E00E/image_thumb_1.png" width="454" height="305" />
          </a>
        </p>
        <p>
 
</p>
        <p>
          <font color="#0000ff" size="2">
            <strong>Improve the performance</strong>
          </font>
        </p>
        <p>
Caching can refer to many concepts. <a name="idd1e22437"></a>The general meaning of
cache is to store a copy of something to prevent the necessity of retrieving it again.
When speaking of Web development, there are three main types of caching: 
</p>
        <ul>
          <li>
            <p>
Caching on the server— Storing<a name="idd1e22455"></a><a name="idd1e22460"></a> a
complete or partially generated resource on the server to keep from having to regenerate
it.
</p>
          </li>
          <li>
            <p>
Caching on the client— Storing<a name="idd1e22478"></a><a name="idd1e22483"></a> a
resource on the client to keep from having to receive the entire resource again.
</p>
          </li>
          <li>
            <p>
Proxy caching— Storing<a name="idd1e22501"></a><a name="idd1e22506"></a> a resource
on a proxy to allow direct replies to an HTTP request rather than having to receive
the entire resource from the origin server again.
</p>
          </li>
        </ul>
        <p>
Although there are many side advantages <a name="idd1e22513"></a><a name="idd1e22518"></a>to
caching, there are three core benefits: 
</p>
        <ul>
          <li>
            <p>
Improve response time from a user perspective— This is what most Web developers focus
on, the user experience.
</p>
          </li>
          <li>
            <p>
Lessen network load— Many Web developers overlook this metric because bandwidth is
often viewed as an expendable resource, where more can be purchased as needed.
</p>
          </li>
          <li>
            <p>
Lessen server load— This metric is more difficult to overlook, as it directly impacts
the user experience in terms of performance and reliability (stressed servers fail
more often).
</p>
          </li>
        </ul>
        <p>
          <strong>
            <font color="#0000ff" size="2">
            </font>
          </strong> 
</p>
        <p>
          <strong>
            <font color="#0000ff" size="2">
            </font>
          </strong> 
</p>
        <p>
          <strong>
            <font color="#0000ff" size="2">
            </font>
          </strong> 
</p>
        <p>
          <strong>
            <font color="#0000ff" size="2">
            </font>
          </strong> 
</p>
        <p>
          <strong>
            <font color="#0000ff" size="2">
            </font>
          </strong> 
</p>
        <p>
          <strong>
            <font color="#0000ff" size="2">
            </font>
          </strong> 
</p>
        <p>
          <strong>
            <font color="#0000ff" size="2">
            </font>
          </strong> 
</p>
        <p>
          <strong>
            <font color="#0000ff" size="2">
            </font>
          </strong> 
</p>
        <p>
          <strong>
            <font color="#0000ff" size="2">
            </font>
          </strong> 
</p>
        <p>
          <strong>
            <font color="#0000ff" size="2">
            </font>
          </strong> 
</p>
        <p>
          <strong>
            <font color="#0000ff" size="2">
            </font>
          </strong> 
</p>
        <p>
          <strong>
            <font color="#0000ff" size="2">
            </font>
          </strong> 
</p>
        <p>
          <strong>
            <font color="#0000ff" size="2">
            </font>
          </strong> 
</p>
        <p>
          <strong>
            <font color="#0000ff" size="2">
            </font>
          </strong> 
</p>
        <p>
          <strong>
            <font color="#0000ff" size="2">
            </font>
          </strong> 
</p>
        <p>
          <strong>
            <font color="#0000ff" size="2">
            </font>
          </strong> 
</p>
        <p>
          <strong>
            <font color="#0000ff" size="2">
            </font>
          </strong> 
</p>
        <p>
          <strong>
            <font color="#0000ff" size="2">
            </font>
          </strong>
        </p>
        <img width="0" height="0" src="http://blog.ilovedoudou.com/aggbug.ashx?id=205ad14d-1123-4af7-9e85-7c02b4eb649a" />
      </div>
    </content>
  </entry>
  <entry>
    <title>Summary of HTTP Developer&amp;rsquo;s Handbook (part2)</title>
    <link rel="alternate" type="text/html" href="http://blog.ilovedoudou.com/PermaLink,guid,446f37a8-bb6b-41e2-875d-b60efc20ff94.aspx" />
    <id>http://blog.ilovedoudou.com/PermaLink,guid,446f37a8-bb6b-41e2-875d-b60efc20ff94.aspx</id>
    <published>2010-03-06T00:51:07.3628379-05:00</published>
    <updated>2010-03-06T00:51:07.3628379-05:00</updated>
    <category term="Life / Career" label="Life / Career" scheme="http://blog.ilovedoudou.com/CategoryView,category,Life%2B%2c%2BCareer.aspx" />
    <category term="Web" label="Web" scheme="http://blog.ilovedoudou.com/CategoryView,category,Web.aspx" />
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
It is important to remember that an HTTP response completes the HTTP transaction.
Many people new to Web development have a difficult time distinguishing between server-side
code (code that executes on the server) and client-side code (code that executes on
the client). Scripting languages such as PHP, ColdFusion, and JSP are executed on
the server, and their output is included in the HTTP response. In fact, their output
is the content of the HTTP response, and most modern Web scripting languages also
allow for some manipulation of the HTTP as well, such as altering or adding headers,
changing status codes, and so on. Once the Web client receives the HTTP response,
the transaction is complete. The Web client will then render the page, execute client-side
scripts such as JavaScript, load images (by issuing separate <tt>GET</tt> requests),
and so on. 
</p>
        <p>
  
</p>
        <p>
          <em>
            <font color="#0080c0">With HTTP/1.1, persistent connections are the default behavior.
This means that the Web server will not close the connection after sending the HTTP
response unless the client intends to close the connection after receiving it. In
this case, the client will include the following header in the HTTP request:</font>
          </em>
        </p>
        <pre>
          <em>
            <font color="#0080c0">Connection: close </font>
          </em>
        </pre>
        <p>
          <em>
            <font color="#0080c0">Alternatively, the server can close the connection upon
sending the HTTP response, although it should be polite and include the same header
as shown previously so that the Web client expects this action.</font>
          </em>
        </p>
        <p>
          <em>
            <font color="#0080c0">
            </font>
          </em>  
</p>
        <p>
An HTTP response is broken into the following three logical pieces: 
</p>
        <ul>
          <li>
            <p>
Status line<a name="idd1e10818"></a><a name="idd1e10825"></a><a name="idd1e10832"></a><a name="idd1e10839"></a></p>
          </li>
          <li>
            <p>
HTTP headers<a name="idd1e10847"></a><a name="idd1e10854"></a><a name="idd1e10861"></a><a name="idd1e10868"></a><a name="idd1e10871"></a></p>
          </li>
          <li>
            <p>
Content<a name="idd1e10881"></a><a name="idd1e10888"></a><a name="idd1e10895"></a><a name="idd1e10902"></a></p>
          </li>
        </ul>
        <p>
An example status line is as follows:
</p>
        <pre>HTTP/1.1 200 OK </pre>
        <p>
The status line contains three elements: 
</p>
        <ul>
          <li>
            <p>
The version of HTTP being used, in the format <tt>HTTP/</tt><tt>x.x</tt></p>
          </li>
          <li>
            <p>
The status code
</p>
          </li>
          <li>
            <p>
A short description of the status code
</p>
          </li>
        </ul>
        <p>
There are three types of HTTP headers allowed in a response: 
</p>
        <ul>
          <li>
            <p>
General headers
</p>
          </li>
          <li>
            <p>
Response headers
</p>
          </li>
          <li>
            <p>
Entity headers
</p>
          </li>
        </ul>
        <p>
  
</p>
        <p>
Status codes are grouped into the following ranges: 
</p>
        <ul>
          <li>
            <p>
Informational (100-199)
</p>
          </li>
          <li>
            <p>
Successful (200-299)
</p>
          </li>
          <li>
            <p>
Redirection (300-399)
</p>
          </li>
          <li>
            <p>
Client error (400-499)
</p>
          </li>
          <li>
            <p>
Server error (500-599)
</p>
          </li>
        </ul>
        <p>
  
</p>
        <ul>
          <li>
100 Continue</li>
          <li>
101 Switching Protocols</li>
          <li>
200 OK</li>
          <li>
400 Bad Request</li>
          <li>
401 Unauthorized</li>
          <li>
403 Forbidden</li>
          <li>
404 Not Found</li>
          <li>
500 Internal Server Error</li>
          <li>
502 Bad Gateway</li>
          <li>
503 Service Unavailable</li>
        </ul>
        <p>
          <tt>Content-Disposition</tt>, combined with a proper <tt>Content-Type</tt> header,
provides the developer absolute control over the interpretation of the resource's
media type<a name="idd1e19751"></a><a name="idd1e19758"></a><a name="idd1e19765"></a><a name="idd1e19772"></a><a name="idd1e19775"></a>.
</p>
        <img width="0" height="0" src="http://blog.ilovedoudou.com/aggbug.ashx?id=446f37a8-bb6b-41e2-875d-b60efc20ff94" />
      </div>
    </content>
  </entry>
  <entry>
    <title>Summary of HTTP Developer&amp;rsquo;s Handbook (part1)</title>
    <link rel="alternate" type="text/html" href="http://blog.ilovedoudou.com/PermaLink,guid,7ecba085-7f36-425a-a981-0379927704ac.aspx" />
    <id>http://blog.ilovedoudou.com/PermaLink,guid,7ecba085-7f36-425a-a981-0379927704ac.aspx</id>
    <published>2010-03-05T16:58:27.030182-05:00</published>
    <updated>2010-03-05T16:58:27.030182-05:00</updated>
    <category term="Web" label="Web" scheme="http://blog.ilovedoudou.com/CategoryView,category,Web.aspx" />
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
 
</p>
        <table border="0" cellspacing="0" cellpadding="2" width="400">
          <tbody>
            <tr>
              <td valign="top" width="200">
                <a href="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/SummaryofHTTPDevelopersHandbookpart1_EF0F/image_2.png">
                  <img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/SummaryofHTTPDevelopersHandbookpart1_EF0F/image_thumb.png" width="337" height="342" />
                </a>
              </td>
              <td valign="top" width="200">
                <a href="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/SummaryofHTTPDevelopersHandbookpart1_EF0F/image_4.png">
                  <img style="border-bottom: 0px; border-left: 0px; margin: 0px auto; display: block; float: none; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/SummaryofHTTPDevelopersHandbookpart1_EF0F/image_thumb_1.png" width="285" height="180" />
                </a>
                <a href="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/SummaryofHTTPDevelopersHandbookpart1_EF0F/image_6.png">
                  <img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/SummaryofHTTPDevelopersHandbookpart1_EF0F/image_thumb_2.png" width="284" height="205" />
                </a>
              </td>
            </tr>
          </tbody>
        </table>
        <p>
        </p>
        <p>
        </p>
        <p>
Server: new a socket –&gt; bind to listen port –&gt; Accept a connection –&gt; send/receive
–&gt;close<br />
Client: new a socket –&gt; connect –&gt;send/receive –&gt; close
</p>
        <p>
          <tt>http://myname:mypass@httphandbook.org:80/mydir/myfile.html?myvar=myvalue#myfrag</tt>
        </p>
        <p>
          <a href="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/SummaryofHTTPDevelopersHandbookpart1_EF0F/image_8.png">
            <img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/SummaryofHTTPDevelopersHandbookpart1_EF0F/image_thumb_3.png" width="440" height="162" />
          </a>
        </p>
        <p>
HTTP is often referred to as a <a name="idd1e5821"></a><a name="idd1e5824"></a><a name="idd1e5829"></a>stateless
protocol. Although this is accurate, it does little to explain the nature of the Web.
All this means, however, is that each transaction is atomic, and there is nothing
required by HTTP that associates one request with another. A transaction refers to
a single HTTP request and the corresponding HTTP response.
</p>
        <p>
When I<a name="idd1e5845"></a><a name="idd1e5852"></a><a name="idd1e5859"></a><a name="idd1e5866"></a> speak
of a connection in HTTP, I refer to a TCP connection. 
</p>
        <p>
A single connection can support multiple HTTP transactions. In many cases, multiple
HTTP transactions are required to properly render a URL in a Web browser due to images
and other associated content. 
</p>
        <p>
        </p>
        <p>
          <a href="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/SummaryofHTTPDevelopersHandbookpart1_EF0F/image_10.png">
            <img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/SummaryofHTTPDevelopersHandbookpart1_EF0F/image_thumb_4.png" width="298" height="118" />
          </a>
        </p>
        <p>
          <strong>Get and Post</strong>
        </p>
        <p>
GET and POST basically allow information to be sent back to the webserver from a browser
(or other HTTP client for that matter). 
</p>
        <p>
Imagine that you have a form on a HTML page and clicking the "submit" button sends
the data in the form back to the server, as "name=value" pairs. 
</p>
        <p>
Choosing GET as the "method" will append all of the data to the URL and it will show
up in the URL bar of your browser. The amount of information you can send back using
a GET is restricted as URLs can only be 1024 characters. 
</p>
        <p>
A POST on the other hand will (typically) send the information through a socket back
to the webserver and it won't show up in the URL bar. You can send much more information
to the server this way - and it's not restricted to textual data either. It is possible
to send files and even binary data such as serialized Java objects! 
</p>
        <p>
A PUT allows you to "put" (upload) a resource (file) on to a webserver so that it
be found under a specified URI. DELETE allows you to delete a resource (file). These
are both additions to HTTP/1.1 and are not usually used. HEAD returns just the HTTP
headers for a resource. TRACE and OPTIONS are also HTTP/1.1 additions and also rarely
used. 
</p>
        <p>
 
</p>
        <p>
Although client-side data validation can add to user convenience by avoiding unnecessary
HTTP transactions, you should never depend on this technique to ensure the data is
valid.
</p>
        <pre>
          <em>GET /search?hl=en&amp;q=HTTP&amp;btnG=Google+Search HTTP/1.1 Host: www.google.com
User-Agent: Mozilla/5.0 Galeon/1.2.0 (X11; Linux i686; U;) Gecko/20020326 Accept:
text/xml,application/xml,application/xhtml+xml,text/html;q=0.9, text/plain;q=0.8,
video/x-mng,image/png,image/jpeg,image/gif;q=0.2, text/css,*/*;q=0.1 Accept-Language:
en Accept-Encoding: gzip, deflate, compress;q=0.9 Accept-Charset: ISO-8859-1, utf-8;q=0.66,
*;q=0.66 Keep-Alive: 300 Connection: keep-alive</em>
        </pre>
        <p>
Broken down, the request line is 
</p>
        <p>
  
</p>
        <p>
An <strong>HTTP request</strong>, which is<a name="idd1e6935"></a><a name="idd1e6940"></a> the
message sent from a Web client to a Web server, is comprised of three basic elements: 
</p>
        <ul>
          <li>
            <p>
Request line<a name="idd1e6953"></a><a name="idd1e6960"></a><a name="idd1e6967"></a></p>
          </li>
          <li>
            <p>
HTTP headers<a name="idd1e6975"></a><a name="idd1e6982"></a><a name="idd1e6989"></a></p>
          </li>
          <li>
            <p>
Content<a name="idd1e6997"></a><a name="idd1e7004"></a><a name="idd1e7011"></a></p>
          </li>
        </ul>
        <p>
The first line of an HTTP request is always the request line. The request line specifies
the request method, the location of the resource, and the version of HTTP being used.
These three elements are delimited by spaces. For example:
</p>
        <pre>GET / HTTP/1.1 </pre>
        <p>
This example specifies the <tt>GET</tt> request method, the resource located at <tt>/</tt> (document
root), and <tt>HTTP/1.1</tt> as the version of protocol used. 
</p>
        <p>
  
</p>
        <p>
The second section of an HTTP request is the headers. HTTP headers include supporting
information that can help to explain the Web client's request more clearly. There
are three types of HTTP headers that can appear<a name="idd1e7039"></a><a name="idd1e7046"></a><a name="idd1e7053"></a> in
a request: 
</p>
        <ul>
          <li>
            <p>
General headers<a name="idd1e7064"></a><a name="idd1e7071"></a><a name="idd1e7078"></a><a name="idd1e7083"></a></p>
          </li>
          <li>
            <p>
Request headers<a name="idd1e7091"></a><a name="idd1e7096"></a></p>
          </li>
          <li>
            <p>
Entity headers<a name="idd1e7104"></a><a name="idd1e7109"></a></p>
          </li>
        </ul>
        <p>
There is no requirement pertaining to the order of the headers. Also, because entity
headers specify information about the content, they are rarely present in HTTP requests. 
</p>
        <p>
  
</p>
        <p>
In general, it is fairly easy to discern which category a header belongs to. Request
headers specifically relate to something unique to an HTTP request, such as the <tt>User-</tt><tt>Agent</tt> header
which identifies the client software being used. General headers are common headers
that can (at least theoretically) be used in either an HTTP request or an HTTP response.
Entity headers relay information about the content itself (the entity). As this request
has no content, it also lacks entity headers. 
</p>
        <p>
  
</p>
        <p>
There are eight request methods in HTTP/1.1: <tt>GET</tt>, <tt>POST</tt>, <tt>PUT</tt>, <tt>DELETE</tt>, <tt>HEAD</tt>, <tt>TRACE</tt>, <tt>OPTIONS</tt>,
and <tt>CONNECT</tt>. HTTP/1.0 specifies three methods (<strong><tt>GET</tt>, <tt>HEAD</tt>,
and <tt>POST</tt></strong>), although four others are implemented by some servers
and clients claiming to be HTTP/1.0. The support for these four other methods (<tt>PUT</tt>, <tt>DELETE</tt>, <tt>LINK</tt>,
and <tt>UNLINK</tt>) is inconsistent and mostly undefined, although they are each
briefly referenced in Appendix D of RFC 1945, the HTTP/1.0 specification. 
</p>
        <p>
  
</p>
        <p>
A <tt><strong><font color="#0000ff">GET</font></strong></tt> request is basically
a request to receive the content located at a specific URL. Obtaining a URL using
the <tt>GET</tt> method allows users to bookmark the URL, create a link to the URL,
email the URL to a friend, and the like. There is a limited amount of data that can
be sent from the Web client using get, and this limit is very inconsistently implemented. 
</p>
        <p>
  
</p>
        <p>
The <tt><strong><font color="#0000ff">POST</font></strong></tt> method is commonly
supported by browsers as a method of submitting form data. 
<br />
As with the query string of a URL, the data in a <tt>POST</tt> consists of name/value
pairs separated by the <tt>&amp;</tt> character. Special characters are URL encoded,
and the <tt>Content-Type</tt> header references this fact. 
</p>
        <p>
  
</p>
        <p>
For many forms, the <tt>POST</tt> method is preferable. 
</p>
        <p>
  
</p>
        <p>
The <tt><strong><font color="#0000ff">PUT</font></strong></tt> method is not<a name="idd1e7782"></a><a name="idd1e7789"></a><a name="idd1e7796"></a><a name="idd1e7801"></a><a name="idd1e7808"></a><a name="idd1e7811"></a> nearly
as common as <tt>GET</tt> or <tt>POST</tt>. However, it is useful in certain situations
because it allows the Web client to send content that will be stored on the Web server.<br />
It should be noted that the <tt>PUT</tt> method is very rarely implemented in Web
clients. A common misconception is that the <tt>PUT</tt> method is required for uploading
files. However, this capability is actually an enhancement to the <tt>POST</tt> method
as identified in RFC 1867, "Form-based File Upload in HTML". 
</p>
        <p>
  
</p>
        <p>
          <tt>
            <font color="#0000ff">HEAD</font>
          </tt> is a very useful <a name="idd1e8021"></a><a name="idd1e8028"></a><a name="idd1e8035"></a><a name="idd1e8040"></a><a name="idd1e8047"></a><a name="idd1e8050"></a>request
method for people who are interested in finding out more information about the way
a certain transaction behaves. The <tt>HEAD</tt> method is supposed to behave exactly
like <tt>GET</tt>, except that the content is not present. Thus, <tt>HEAD</tt> is
like a normal <tt>GET</tt> request with all of the HTML stripped away. 
</p>
        <p>
  
</p>
        <p>
          <tt>
            <font color="#0000ff">TRACE</font>
          </tt> is another diagnostic<a name="idd1e8157"></a><a name="idd1e8164"></a><a name="idd1e8171"></a><a name="idd1e8176"></a><a name="idd1e8183"></a><a name="idd1e8186"></a> request
method. This method allows the client to gain more perspective into any intermediary
proxies that lie between the client and the server. As each proxy forwards the <tt>TRACE</tt> request
on route to the destination Web server, it will add itself to the <tt>Via</tt> header,
with the first proxy being responsible for adding the <tt>Via</tt> header. When the
response is given, the content is actually the final request including the <tt>Via</tt> header. 
</p>
        <p>
  
</p>
        <p>
Sometimes it is helpful to <a name="idd1e8236"></a><a name="idd1e8243"></a><a name="idd1e8250"></a><a name="idd1e8255"></a><a name="idd1e8262"></a><a name="idd1e8265"></a>simply
identify the capabilities of the Web server you want to interact with prior to actually
making a request. For this purpose, HTTP provides the <tt><font color="#0000ff"><strong>OPTIONS</strong></font></tt> request
method. 
</p>
        <p>
  
</p>
        <p>
The <tt>CONNECT</tt> request method is<a name="idd1e8376"></a><a name="idd1e8383"></a><a name="idd1e8390"></a><a name="idd1e8395"></a><a name="idd1e8402"></a><a name="idd1e8405"></a> reserved
explicitly for use by intermediary servers to create a tunnel to the destination server.
The intermediary, not the HTTP client, issues the <tt><font color="#0000ff"><strong>CONNECT</strong></font></tt> request
to the destination server.<br />
The most common use of the <tt>CONNECT</tt> method is by a Web client that must use
a proxy to request a secure resource using SSL (Secure Sockets Layer) or TLS (Transport
Layer Security). The client will tunnel the request through the proxy so that the
proxy will simply route the HTTP messages to and from the Web server without trying
to examine or interpret them. 
</p>
        <p>
 
</p>
        <p>
Accept Header
</p>
        <p>
Authorization Header<br />
Once the browser has successfully authenticated with a Web server in this way, it
will appear to a user as if all further requests do not require reauthentication.
However, due to the stateless nature of the Web, every request must include the <tt>Authorization</tt> header,
otherwise the server will respond with a <tt>401 Unauthorized</tt> response. The convenient
behavior of most modern Web browsers involves the browser storing the access credentials
and sending the <tt>Authorization</tt> header with all HTTP requests for a URL within
a domain previously discovered to be protected. Because this utilizes the browser's
memory, this convenience lasts as long as the browser (at least one instance of the
browser) remains active, and the user will be unaware that this authentication takes
place in subsequent requests. This can be a very important factor when debugging HTTP
authentication, because if you receive a <tt>401 Unauthorized</tt> response without
being prompted for a username and password, this suggests that the browser is using
incorrect credentials in the <tt>Authorization</tt> header. Restarting the browser
will resolve this situation.
</p>
        <img width="0" height="0" src="http://blog.ilovedoudou.com/aggbug.ashx?id=7ecba085-7f36-425a-a981-0379927704ac" />
      </div>
    </content>
  </entry>
  <entry>
    <title>.Net review (part 2)</title>
    <link rel="alternate" type="text/html" href="http://blog.ilovedoudou.com/PermaLink,guid,389d2abf-ee9d-4921-8234-11cdc21b57e3.aspx" />
    <id>http://blog.ilovedoudou.com/PermaLink,guid,389d2abf-ee9d-4921-8234-11cdc21b57e3.aspx</id>
    <published>2010-03-05T15:13:20.8387632-05:00</published>
    <updated>2010-03-05T15:13:20.8387632-05:00</updated>
    <category term="DotNet" label="DotNet" scheme="http://blog.ilovedoudou.com/CategoryView,category,DotNet.aspx" />
    <category term="Life / Career" label="Life / Career" scheme="http://blog.ilovedoudou.com/CategoryView,category,Life%2B%2c%2BCareer.aspx" />
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <font color="#0000ff" size="3">
            <strong>Form 2.0 data binding</strong>
          </font>
        </p>
        <pre class="csharpcode">Binding nameBinding = <span class="kwrd">new</span> Binding(<span class="str">"Text"</span>, <span class="kwrd">this</span>.raceCarDriver, <span class="str">"Name"</span>, <span class="kwrd">true</span>); <span class="kwrd">this</span>.nameTextBox.DataBindings.Add(nameBinding);
or <span class="kwrd">this</span>.nameTextBox.DataBindings.Add( <span class="str">"Text"</span>, <span class="kwrd">this</span>.raceCarDriver, <span class="str">"Name"</span>);
The minimum implementation that <span class="kwrd">is</span> considered a list data
source by the Windows Forms binding engine <span class="kwrd">is</span> a <span class="kwrd">class</span> that
implements the IList <span class="kwrd">interface</span> (from System.Collections). <span class="kwrd">this</span>.BindingManager.Position
= 0; RefreshItems(); <span class="kwrd">this</span>.raceCarDriversListBox.DataSource
= <span class="kwrd">this</span>.raceCarDrivers; <span class="kwrd">this</span>.raceCarDriversListBox.DisplayMember
= <span class="str">"Name"</span>; <span class="kwrd">void</span> addButton_Click(<span class="kwrd">object</span> sender,
EventArgs e) { <span class="rem">// Add item to list data source directly</span> RaceCarDriver
raceCarDriver = <span class="kwrd">new</span> RaceCarDriver(<span class="str">"Nelson
Piquet"</span>, 300); <span class="kwrd">this</span>.raceCarDrivers.Add(raceCarDriver); <span class="rem">//
Select new item</span><span class="kwrd">this</span>.BindingManager.Position = <span class="kwrd">this</span>.BindingManager.Count
- 1; } <span class="kwrd">private</span><span class="kwrd">void</span> deleteButton_Click(<span class="kwrd">object</span> sender,
EventArgs e) { <span class="rem">// Remove item from list data source directly</span><span class="kwrd">this</span>.raceCarDrivers.Remove(
(RaceCarDriver)<span class="kwrd">this</span>.BindingManager.Current); }</pre>
        <style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>
        <pre>
        </pre>
        <p>
          <strong>BindingList&lt;T&gt;-&gt;IBindingList-&gt;IList</strong>
          <br />
BindingList&lt;T&gt; nicely implements the list management (AllowEdit, AllowNew, AllowRemove,
and AddNew) and change notification (SupportsChangeNotification, ListChanged) functional
subsets of IBindingList.<sup><a href="#ch16fn05">[5]</a></sup> And because it's generic,
it can turn any type into a strongly typed list data source with data-binding-savvy
list management and change notification using something like the following code<br /></p>
        <h6>Two-Way Item Change Synchronization
</h6>
        <p>
When the values in a DataGridView row are changed, DataGridView automatically replicates
the changes to the bound list data source. Similarly, when changes are made to an
item in the list data source of BindingList&lt;T&gt;, an item change notification
is broadcast to all bound controls. 
</p>
        <p>
  
</p>
        <p>
BindingList&lt;T&gt; allows us to use almost any class to create a data-binding-savvy
strongly typed list data source. However, some item classes come already associated
with their own collection classes. Although any collection class that implements IList
can be used as a list data source, you don't get full-flavor data binding if you don't
implement IBindingListnamely, support for two-way list and item change notification. 
</p>
        <p>
To gain this support and to avoid the highly involved implementation of IBindingList
ourselves, we'd love to be able to "upgrade" an existing IList implementation to IBindingList.
The class that performs this upgrade for you is <strong>BindingSource</strong>. 
</p>
        <p>
The BindingSource component (from System.Windows.Forms) consumes either item types
or list types and exposes them as IBindingList implementations. 
</p>
        <p>
  
</p>
        <p>
if you need to implement a VCR-type control to navigate the items in a data source,
you don't have to acquire a BindingManager and you don't have to manually create your
own navigation methods. Instead, you simply rely on the BindingSource to manage currency
and use its currency-oriented methods as required: 
</p>
        <p>
  
</p>
        <p>
void moveFirstButton_Click(object sender, EventArgs e) 
</p>
        <p>
{ this.employeesBindingSource.MoveFirst(); RefreshItems(); } 
</p>
        <p>
  
</p>
        <p>
Master-Detail binding<br /><a href="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/d0ca6d3651bd.Netreviewpart2_D671/image_2.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/d0ca6d3651bd.Netreviewpart2_D671/image_thumb.png" width="536" height="246" /></a></p>
        <p>
 
</p>
        <p>
          <strong>
            <font color="#0000ff" size="2">Why [STAThread]</font>
          </strong>
        </p>
        <p>
          <code>When the STAThreadAttribute is applied, it changes the apartment state of the
current thread to be single threaded. Without getting into a huge discussion about
COM and threading, this attribute ensures the communication mechanism between the
current thread and other threads that may want to talk to it via COM. When you're
using Windows Forms, depending on the feature you're using, it may be using COM interop
in order to communicate with operating system components. Good examples of this are
the Clipboard and the File Dialogs.</code>
        </p>
        <p>
          <code>
            <font color="#0000ff" size="2">
              <strong>SingleInstanceApplication</strong>
            </font>
          </code>
        </p>
        <p>
// SingleInstanceApplication.cs 
<br />
class SingleInstanceApplication : <strong>WindowsFormsApplicationBase</strong><br />
{ ... protected override void OnCreateMainForm() { this.MainForm = new MainForm();
}<code><font color="#0000ff" size="2"><strong><br /></strong></font></code></p>
        <img width="0" height="0" src="http://blog.ilovedoudou.com/aggbug.ashx?id=389d2abf-ee9d-4921-8234-11cdc21b57e3" />
      </div>
    </content>
  </entry>
  <entry>
    <title>.Net review 1</title>
    <link rel="alternate" type="text/html" href="http://blog.ilovedoudou.com/PermaLink,guid,e0ded28d-bb6b-4275-9dd9-8b04cb0c4aa4.aspx" />
    <id>http://blog.ilovedoudou.com/PermaLink,guid,e0ded28d-bb6b-4275-9dd9-8b04cb0c4aa4.aspx</id>
    <published>2010-03-04T14:57:29.1815327-05:00</published>
    <updated>2010-03-05T10:49:13.873301-05:00</updated>
    <category term="DotNet" label="DotNet" scheme="http://blog.ilovedoudou.com/CategoryView,category,DotNet.aspx" />
    <category term="Life / Career" label="Life / Career" scheme="http://blog.ilovedoudou.com/CategoryView,category,Life%2B%2c%2BCareer.aspx" />
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <strong>
            <font color="#0000ff">CLR and .NET Framework</font>
          </strong>
        </p>
        <p>
The CLR is the runtime for executing managed code. C# is one of several managed<br />
languages that get compiled into managed code. Managed code is packaged into an<br />
assembly, in the form of either an executable file (an .exe) or a library (a .dll),
along<br />
with type information, or metadata.<br /><br />
Managed code is represented in Intermediate Language or IL. When the CLR loads<br />
an assembly, it converts the IL into the native code of the machine, such as x86.
This<br />
conversion is done by the CLR’s JIT (Just-In-Time) compiler. An assembly retains 
</p>
        <p>
almost all of the original source language constructs, which makes it easy to inspect<br />
and even generate code dynamically.<br /></p>
        <p>
The CLR performs as a host for numerous runtime services. Examples of these services<br />
include memory management, the loading of libraries, and security services.<br />
The CLR is language-neutral, allowing developers to build applications in multiple<br />
languages (e.g., C#, Visual Basic .NET, Managed C++, Delphi.NET, Chrome .NET,<br />
and J#). 
</p>
        <p>
  
</p>
        <p>
  
</p>
        <p>
          <strong>
            <font color="#0000ff">How the Garbage Collector Works:</font>
          </strong>
        </p>
        <p>
The GC begins with its root object references, and walks the object graph, marking<br />
all the objects it touches as reachable. Once this process is complete, all objects
that<br />
have not been marked are considered unused, and are subject to garbage collection.<br />
Unused objects without finalizers are immediately discarded; unused objects with<br />
finalizers are enqueued for processing on the finalizer thread after the GC is complete.<br />
These objects then become eligible for collection in the next GC for the object’s<br />
generation (unless resurrected). 
</p>
        <p>
  
</p>
        <p>
The remaining “live” objects are then shifted to the start of the heap (compacted),<br />
freeing space for more objects. This compaction serves two purposes: it avoids 
</p>
        <p>
memory fragmentation, and it allows the GC to employ a very simple strategy when<br />
allocating new objects, which is to always allocate memory at the end of the heap.<br />
This avoids the potentially time-consuming task of maintaining a list of free memory<br />
segments. 
</p>
        <p>
  
</p>
        <p>
If there is insufficient space to allocate memory for a new object after garbage<br />
collection, and the operating system is unable to grant further memory, an<br />
OutOfMemoryException is thrown. 
</p>
        <p>
  
</p>
        <p>
          <em>Generational collection<br /></em>The most important optimization is that the GC is generational. This takes advantage<br />
of the fact that although many objects are allocated and discarded rapidly, certain<br />
objects are long-lived and thus don’t need to be traced during every collection.<br />
Basically, the GC divides the managed heap into three generations. Objects that have<br />
just been allocated are in Gen0 and objects that have survived one collection cycle<br />
are in Gen1; all other objects are in Gen2. 
</p>
        <p>
  
</p>
        <p>
          <em>The large object heap</em>
          <br />
The GC uses a separate heap called the Large Object Heap (LOH) for objects larger<br />
than a certain threshold (currently 85,000 bytes). This avoids excessive Gen0<br />
collections—without the LOH, allocating a series of 16 MB objects might trigger a<br />
Gen0 collection after every allocation. 
</p>
        <p>
The LOH is not subject to compaction, because moving large blocks of memory<br />
during garbage collection would be prohibitively expensive. This has two<br />
consequences: 
</p>
        <p>
1. Allocations can be slower<br />
2. The LOH is subject to fragmentation 
</p>
        <p>
The large object heap is also nongenerational: all objects are treated as Gen2. 
</p>
        <p>
  
</p>
        <p>
          <em>Concurrent and background collection</em>
        </p>
        <p>
The GC must freeze (block) your execution threads for periods during a collection.<br />
This includes the entire period during which a Gen0 or Gen1 collection takes place.<br />
The GC makes a special attempt, though, at allowing threads to run during a Gen2<br />
collection 
</p>
        <p>
  
</p>
        <p>
Forcing Garbage Collection (not recommend) 
</p>
        <p>
GC.Collect() 
</p>
        <p>
  
</p>
        <p>
          <strong>A good guideline is to implement IDisposable yourself if any field in your
class is assigned an object that implements IDisposable. </strong>(Such as System.Timers.Timer)(System.Threading.Timer
is different) 
</p>
        <p>
  
</p>
        <p>
Monitor the memory leaks: long memoryUsed = GC.GetTotalMemory (true); 
</p>
        <p>
  
</p>
        <p>
Occasionally, it’s useful to hold a reference to an object that’s “invisible” to the
GC<br />
in terms of keeping the object alive. This is called a <strong><font color="#0000ff">weak
reference</font></strong>, and is implemented<br />
by the System.WeakReference class. 
</p>
        <p>
  
</p>
        <p>
One use for WeakReference is to cache large object graphs.<br /><a title="http://www.shafqatahmed.com/2008/01/weakreference-b.html" href="http://www.shafqatahmed.com/2008/01/weakreference-b.html">http://www.shafqatahmed.com/2008/01/weakreference-b.html</a></p>
        <p>
  
</p>
        <p>
  
</p>
        <p>
          <strong>
            <font color="#0000ff">Asynchronous Methods</font>
          </strong>
        </p>
        <p>
asynchronous programming model or APM<br /></p>
        <p>
An asynchronous method aims never to block any thread, instead using a pattern of<br />
returning with a callback. 
</p>
        <p>
  
</p>
        <p>
The end goal of the APM is thread economy. 
</p>
        <p>
The purpose of asynchronous methods isn’t to<br />
provide a convenient mechanism for executing a method in parallel with the caller;<br />
it’s to optimize thread resources. 
</p>
        <p>
  
</p>
        <p>
Here’s the golden rule of the APM: <strong>Make good use of the CPU, or exit with
a callback!</strong></p>
        <p>
          <strong>
          </strong>  
</p>
        <p>
The primary use for asynchronous methods is handling many potentially longrunning<br />
concurrent requests—typically over slow network connections. 
</p>
        <p>
  
</p>
        <p>
IAsyncResult BeginXXX (in/ref-args, AsyncCallback callback, object state);<br />
return-type EndXXX (out/ref-args, IAsyncResult asyncResult);<br />
public delegate void AsyncCallback (IAsyncResult ar); 
</p>
        <p>
  
</p>
        <p>
To avoid blocking, you will nearly always call the EndXXX method from inside the<br />
callback method. Callbacks always run on pooled threads. 
</p>
        <p>
  
</p>
        <p>
          <a href="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/fb9127b647d3.Netreview1_D2BC/image_2.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/fb9127b647d3.Netreview1_D2BC/image_thumb.png" width="574" height="192" />
          </a>
        </p>
        <p>
  
</p>
        <p>
          <a title="http://en.csharp-online.net/CSharp_Delegates_and_Events%E2%80%94Asynchronous_method_calls" href="http://en.csharp-online.net/CSharp_Delegates_and_Events%E2%80%94Asynchronous_method_calls">http://en.csharp-online.net/CSharp_Delegates_and_Events%E2%80%94Asynchronous_method_calls</a>
          <br />
          <a title="http://msdn.microsoft.com/en-us/library/h80ttd5f.aspx" href="http://msdn.microsoft.com/en-us/library/h80ttd5f.aspx">http://msdn.microsoft.com/en-us/library/h80ttd5f.aspx</a>
        </p>
        <p>
          <font color="#0000ff" size="3">Collections</font>
        </p>
        <p>
ICollection Properties
</p>
        <p>
          <a href="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/fb9127b647d3.Netreview1_D2BC/image_6.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/fb9127b647d3.Netreview1_D2BC/image_thumb_2.png" width="510" height="253" />
          </a>
        </p>
        <p>
          <a href="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/fb9127b647d3.Netreview1_D2BC/image_4.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blog.ilovedoudou.com/content/binary/WindowsLiveWriter/fb9127b647d3.Netreview1_D2BC/image_thumb_1.png" width="557" height="198" />
          </a>
        </p>
        <p>
IComparer 
<br />
Copmare method
</p>
        <p>
IEqualityComparer<br />
GetHashCode, Equals
</p>
        <p>
SortedList calss is a dictionary.
</p>
        <p>
          <font color="#0000ff" size="2">
            <strong>Race conditions and deadlocks</strong>
          </font>
        </p>
        <p>
        </p>
        <p>
          <a title="http://support.microsoft.com/kb/317723" href="http://support.microsoft.com/kb/317723">http://support.microsoft.com/kb/317723</a>
        </p>
        <p>
A <i>race condition</i> occurs when two threads access a shared variable at the same
time. The first thread reads the variable, and the second thread reads the same value
from the variable. Then the first thread and second thread perform their operations
on the value, and they race to see which thread can write the value last to the shared
variable. The value of the thread that writes its value last is preserved, because
the thread is writing over the value that the previous thread wrote.
</p>
        <p>
A <i>deadlock</i> occurs when two threads each lock a different variable at the same
time and then try to lock the variable that the other thread already locked. As a
result, each thread stops executing and waits for the other thread to release the
variable. Because each thread is holding the variable that the other thread wants,
nothing occurs, and the threads remain deadlocked.
</p>
        <img width="0" height="0" src="http://blog.ilovedoudou.com/aggbug.ashx?id=e0ded28d-bb6b-4275-9dd9-8b04cb0c4aa4" />
      </div>
    </content>
  </entry>
  <entry>
    <title>Windows Form Threading Programming</title>
    <link rel="alternate" type="text/html" href="http://blog.ilovedoudou.com/PermaLink,guid,3c7fb74b-7e6d-4e21-8c71-bcfe739b2fb5.aspx" />
    <id>http://blog.ilovedoudou.com/PermaLink,guid,3c7fb74b-7e6d-4e21-8c71-bcfe739b2fb5.aspx</id>
    <published>2010-03-03T16:59:53.6618883-05:00</published>
    <updated>2010-03-03T16:59:53.6618883-05:00</updated>
    <category term="DotNet" label="DotNet" scheme="http://blog.ilovedoudou.com/CategoryView,category,DotNet.aspx" />
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <a title="http://msdn.microsoft.com/en-us/library/ms951089.aspx" href="http://msdn.microsoft.com/en-us/library/ms951089.aspx">http://msdn.microsoft.com/en-us/library/ms951089.aspx</a>
          <br />
          <a title="http://msdn.microsoft.com/en-us/library/ms951109.aspx" href="http://msdn.microsoft.com/en-us/library/ms951109.aspx">http://msdn.microsoft.com/en-us/library/ms951109.aspx</a>
          <br />
          <a title="http://msdn.microsoft.com/en-us/library/ms951109.aspx" href="http://msdn.microsoft.com/en-us/library/ms951109.aspx">http://msdn.microsoft.com/en-us/library/ms951109.aspx</a>
        </p>
        <img width="0" height="0" src="http://blog.ilovedoudou.com/aggbug.ashx?id=3c7fb74b-7e6d-4e21-8c71-bcfe739b2fb5" />
      </div>
    </content>
  </entry>
  <entry>
    <title>Understanding the Built-In User and Group Accounts in IIS 7.0</title>
    <link rel="alternate" type="text/html" href="http://blog.ilovedoudou.com/PermaLink,guid,a28e2b8e-a25f-452e-8537-ee2f5bb0ff8c.aspx" />
    <id>http://blog.ilovedoudou.com/PermaLink,guid,a28e2b8e-a25f-452e-8537-ee2f5bb0ff8c.aspx</id>
    <published>2010-03-01T11:31:47.9328314-05:00</published>
    <updated>2010-03-01T11:31:47.9328314-05:00</updated>
    <category term="DotNet / ASP" label="DotNet / ASP" scheme="http://blog.ilovedoudou.com/CategoryView,category,DotNet%2B%2c%2BASP.aspx" />
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <a title="http://learn.iis.net/page.aspx/140/understanding-the-built-in-user-and-group-accounts-in-iis-70/" href="http://learn.iis.net/page.aspx/140/understanding-the-built-in-user-and-group-accounts-in-iis-70/">http://learn.iis.net/page.aspx/140/understanding-the-built-in-user-and-group-accounts-in-iis-70/</a>
        </p>
        <p>
In previous versions of IIS, we had a local account created at install time called
IUSR_MachineName. The IUSR_MachineName account was the default identity used by IIS
whenever anonymous authentication was enabled. This was used by both the FTP and HTTP
services.  
</p>
        <p>
There was also had a group called IIS_WPG, used as a container for all the application
pool identities. We made sure all the appropriate resources on the system had the
correct permissions set for the IIS_WPG group during IIS setup so that an administrator
only needed to add their identity to that group when they created a new application
pool account. 
</p>
        <p>
This model worked well, but had its drawbacks: the IUSR_MachineName account and IIS_WPG
group were both local to the system it was created on. Every account and group within
Windows is given a unique number called a SID (security identifier) that distinguishes
it from other accounts. When an ACL is created only the SID is used. As part of our
design in previous versions of IIS, we had included the IUSR_MachineName in the metabase.xml
file so that if you tried to copy the metabase.xml from one machine to another, it
would not work--the account on the other machine would have a different name. 
</p>
        <p>
In addition, you could not just 'xcopy /o' ACLs from one machine to another since
the SIDs were different machine to machine. A work around was to use domain accounts--but
that required adding an active directory to the infrastructure. The IIS_WPG group
had similar issues with permissions. If you set ACLs on one machine's file system
for IIS_WPG and tried to 'xcopy /o' those over to another machine, it would fail.
The IIS team heard this feedback and improved this experience by using a built-in
account and group in IIS 7.0. 
</p>
        <p>
A built-in account and group are guaranteed by the operating system to always have
a unique SID. IIS 7.0 has taken this further and ensured the actual names used by
the new account and group will never be localized. For example, regardless of the
language of Windows you install, the IIS account name will always be IUSR and the
group name will be IIS_IUSRS. 
</p>
        <p>
In summary, IIS 7.0 offers: 
</p>
        <ul>
          <li>
The IUSR built-in account replaces the IUSR_MachineName account 
</li>
          <li>
The IIS_IUSRS built-in group replaces the IIS_WPG group 
</li>
        </ul>
        <p>
Since the IUSR account is a built in account, it no longer needs a password. Logically,
think of it as being the same as NETWORKSERVICE or LOCALSERVICE accounts. Both the
new IUSR account and IIS_IUSRS group are discussed in greater depth in the sections
below. 
</p>
        <img width="0" height="0" src="http://blog.ilovedoudou.com/aggbug.ashx?id=a28e2b8e-a25f-452e-8537-ee2f5bb0ff8c" />
      </div>
    </content>
  </entry>
  <entry>
    <title>VSTO resources</title>
    <link rel="alternate" type="text/html" href="http://blog.ilovedoudou.com/PermaLink,guid,31e859ca-3ade-4e85-a301-598cf3c9fd58.aspx" />
    <id>http://blog.ilovedoudou.com/PermaLink,guid,31e859ca-3ade-4e85-a301-598cf3c9fd58.aspx</id>
    <published>2010-02-25T16:57:49.8102705-05:00</published>
    <updated>2010-02-26T16:57:25.9900706-05:00</updated>
    <category term="DotNet / VSTO" label="DotNet / VSTO" scheme="http://blog.ilovedoudou.com/CategoryView,category,DotNet%2B%2c%2BVSTO.aspx" />
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
Category<br /><a title="http://stackoverflow.com/questions/2007136/is-it-possible-to-rename-outlook-category-programmatically" href="http://stackoverflow.com/questions/2007136/is-it-possible-to-rename-outlook-category-programmatically">http://stackoverflow.com/questions/2007136/is-it-possible-to-rename-outlook-category-programmatically</a><br /><a title="http://www.officekb.com/Uwe/Forum.aspx/outlook-prog-addins/3142/Apply-Categories-to-other-users-Outlook-2007" href="http://www.officekb.com/Uwe/Forum.aspx/outlook-prog-addins/3142/Apply-Categories-to-other-users-Outlook-2007">http://www.officekb.com/Uwe/Forum.aspx/outlook-prog-addins/3142/Apply-Categories-to-other-users-Outlook-2007</a><br /><a title="http://social.msdn.microsoft.com/Forums/en-CA/vsto/thread/2131cb1c-f839-4a03-afa8-417fc7d09caf" href="http://social.msdn.microsoft.com/Forums/en-CA/vsto/thread/2131cb1c-f839-4a03-afa8-417fc7d09caf">http://social.msdn.microsoft.com/Forums/en-CA/vsto/thread/2131cb1c-f839-4a03-afa8-417fc7d09caf</a><br />
Filter the items by category  <a title="http://social.msdn.microsoft.com/Forums/en-US/vsto/thread/0cc73e64-f357-4a83-a193-0b40643ceec6" href="http://social.msdn.microsoft.com/Forums/en-US/vsto/thread/0cc73e64-f357-4a83-a193-0b40643ceec6">http://social.msdn.microsoft.com/Forums/en-US/vsto/thread/0cc73e64-f357-4a83-a193-0b40643ceec6</a><br /><a title="http://msdn.microsoft.com/en-us/library/bb220369.aspx" href="http://msdn.microsoft.com/en-us/library/bb220369.aspx">http://msdn.microsoft.com/en-us/library/bb220369.aspx</a><br />
Enumerate Outlook Categories <a title="http://social.msdn.microsoft.com/forums/en-US/vsto/thread/96a21b1b-dc42-43fe-a209-2b661afdc8c8/" href="http://social.msdn.microsoft.com/forums/en-US/vsto/thread/96a21b1b-dc42-43fe-a209-2b661afdc8c8/">http://social.msdn.microsoft.com/forums/en-US/vsto/thread/96a21b1b-dc42-43fe-a209-2b661afdc8c8/</a></p>
        <p>
Deployment<br /><a title="http://msdn.microsoft.com/en-us/library/cc563937.aspx" href="http://msdn.microsoft.com/en-us/library/cc563937.aspx">http://msdn.microsoft.com/en-us/library/cc563937.aspx</a><br /><a title="http://blogs.msdn.com/vsto/archive/2008/04/10/deploying-an-office-solution-using-windows-installer-mary-lee.aspx" href="http://blogs.msdn.com/vsto/archive/2008/04/10/deploying-an-office-solution-using-windows-installer-mary-lee.aspx">http://blogs.msdn.com/vsto/archive/2008/04/10/deploying-an-office-solution-using-windows-installer-mary-lee.aspx</a><br /><a title="http://social.msdn.microsoft.com/Forums/en-US/vsto/thread/975eee4a-0e01-40b7-a94f-59981909f748/" href="http://social.msdn.microsoft.com/Forums/en-US/vsto/thread/975eee4a-0e01-40b7-a94f-59981909f748/">http://social.msdn.microsoft.com/Forums/en-US/vsto/thread/975eee4a-0e01-40b7-a94f-59981909f748/</a><br /><a title="http://weblogs.asp.net/mnissen/archive/2005/07/01/417148.aspx" href="http://weblogs.asp.net/mnissen/archive/2005/07/01/417148.aspx">http://weblogs.asp.net/mnissen/archive/2005/07/01/417148.aspx</a><br />
ClickOnce <a title="http://msdn.microsoft.com/en-us/library/bb821233.aspx" href="http://msdn.microsoft.com/en-us/library/bb821233.aspx">http://msdn.microsoft.com/en-us/library/bb821233.aspx</a><br />
Certificate <a title="http://msdn.microsoft.com/en-us/library/ms996418.aspx" href="http://msdn.microsoft.com/en-us/library/ms996418.aspx">http://msdn.microsoft.com/en-us/library/ms996418.aspx</a></p>
        <img width="0" height="0" src="http://blog.ilovedoudou.com/aggbug.ashx?id=31e859ca-3ade-4e85-a301-598cf3c9fd58" />
      </div>
    </content>
  </entry>
</feed>