<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://community.icburner.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>VS2010学习</title><link>http://community.icburner.com/blogs/vs2010tests/default.aspx</link><description /><dc:language>en</dc:language><generator>CommunityServer 2008.5 SP2 (Build: 40407.4157)</generator><item><title>Simplifying Entity Framework: Data-Driven Design</title><link>http://community.icburner.com/blogs/vs2010tests/archive/2009/12/29/simplifying-entity-framework-data-driven-design.aspx</link><pubDate>Tue, 29 Dec 2009 02:47:13 GMT</pubDate><guid isPermaLink="false">7695cfbe-8499-488a-81cc-9a443df3b4ce:2000</guid><dc:creator>革命</dc:creator><slash:comments>0</slash:comments><description>&lt;h3&gt;&amp;#160;&lt;/h3&gt;  &lt;ul&gt;   &lt;li&gt;Posted by &lt;a href="http://www.olegsych.com/author/olegsych/"&gt;Oleg Sych&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;December 27, 2009 &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;As &lt;a href="http://msdn.microsoft.com/en-us/library/bb399567.aspx"&gt;described on MSDN&lt;/a&gt;, ADO.NET Entity Framework is a set of technologies that enables developers to work with data in the form of domain-specific objects and properties, such as customers and customer addresses without having to concern themselves with the underlying database tables and columns where this data is stored. Developers can use Entity SQL and traditional ADO.NET reader/adapter/dataset patterns or the new LINQ to Entities to write their code. With LINQ to Entities, the Entity Framework generates strongly-typed entity classes you can use in application code and rely on the runtime to figure out how the data needs to be retrieved from the underlying data source.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/2654.clip_5F00_image001_5F00_02112128.gif"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="clip_image001" border="0" alt="clip_image001" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/7532.clip_5F00_image001_5F00_thumb_5F00_51E9D664.gif" width="240" height="225" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Design of Entity Framework has been inspired by the traditional methodology of relational database design which suggests creating a conceptual (class) model, transforming it into logical (relational) model and finally into physical database model. While these activities are typically performed during design and initial implementation of the information system, the Entity Framework implements the physical model, makes the conceptual model a first-class citizen and explicitly defines the mapping model.&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Conceptual model defines entities and their relationships from the application point of view. This model is defined using Conceptual Schema Definition Language (CSDL) and stored in a separate .csdl file or as part of a combined .edmx file in your project. &lt;/li&gt;    &lt;li&gt;Storage model defines entities and their relationships from the database point of view. This model is defined using Store Schema Definition Language (SSDL) and stored in a separate .ssdl file or as part of a combined .edmx file in your project. &lt;/li&gt;    &lt;li&gt;Mapping model defines how conceptual model translates into storage model. It is defined using Mapping Specification Language (MSL) and stored in a separate .msl file or as part of a combined .edmx file in your project. &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;The Entity Framework uses these XML-based models to transform create, read, update, and delete operations against entities and relationships in the conceptual model to equivalent operations in the data source. The storage and mapping models can change as needed without requiring changes to the conceptual model, data classes, or application code. Because storage models are provider-specific, you can work with a consistent conceptual model across various data sources. The Entity Data Model even supports mapping entities in the conceptual model to stored procedures in the data source.&lt;/p&gt;  &lt;p&gt;&lt;b&gt;What is wrong with this picture?&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;Entity Framework was designed to overcome the &lt;a href="http://en.wikipedia.org/wiki/Object-relational_impedance_mismatch"&gt;object-relational impedance mismatch&lt;/a&gt; and allow you to hide a difficult-to-use legacy database schema behind a modern, object-oriented entity model and make developers more productive. This description almost sounds to good to be true. Unfortunately, just like other frameworks designed to solve complex problems, the Entity Framework tends to make simple things difficult.&lt;/p&gt;  &lt;p&gt;Having three separate database layers (or models) in the Entity Data Model means having each entity represented three times, each from a different point of view. Each time you need to make a change in your database model, which also needs to be implemented in the application, you have to make it three times. Take adding a new column to a table as an example. No matter in which order you do it, you still have to add a new property to the conceptual model, a new column to the storage model and a new mapping from one to the other. This task is tedious and error prone even with the best modeling tools imaginable. Unfortunately, Entity Framework designer limits you to a single diagram, which gradually becomes more difficult to use as the number of entities increases, becoming virtually useless when it exceeds 50.&lt;/p&gt;  &lt;p&gt;In simplistic terms, this all means that Entity Data Model is three times as complex as a traditional database model. To implement all but trivial logic, either one developer has to understand all three models or you have to have two or more people involved in implementing it. In the end, you have to spend three times more effort to develop and maintain the EDM, you are three times more likely to make mistakes, i.e. the cost of having the EDM in your solutions is three times higher than the cost of a solution that uses a single hypothetical data model.&lt;/p&gt;  &lt;p&gt;&lt;b&gt;What is the alternative?&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;Majority of information systems in existence today are built using relational databases and data-oriented code. A tremendous amount of tooling, knowledge and experience has been developed over the past two decades by the industry, making low-cost development resources readily available. Although solving the object-relational impedance mismatch sounds very good in theory, in practice, the overall cost of such a solution is typically higher, in part due to additional effort required to maintain three separate database models and in part due to additional knowledge and experience required from developers.&lt;/p&gt;  &lt;p&gt;However, the existing as well as new information systems could benefit tremendously from having a modern, strongly-typed, LINQ-enabled, automatically generated data access layer (DAL). Such a DAL would allow to significantly reduce the amount of plumbing code developers have to write today with &lt;a href="http://msdn.microsoft.com/en-us/library/system.data.common.dbconnection.aspx"&gt;DbConnection&lt;/a&gt;, &lt;a href="http://msdn.microsoft.com/en-us/library/system.data.common.dbdatareader.aspx"&gt;DbDataReader&lt;/a&gt; and &lt;a href="http://msdn.microsoft.com/en-us/library/system.data.dataset.aspx"&gt;DataSet&lt;/a&gt; classes without requiring significant changes to the application architecture. In other words, as long as the effort required to maintain such a DAL is less than the effort required to maintain the data access code manually, we can take advantage of the language and data access enhancements offered by the current version of the .NET framework while reducing the overall cost of the information systems.&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Entity Framework DAL generator in T4 Toolbox&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;In order to implement an automatically generated DAL based on Entity Framework today, you would have to use &lt;a href="http://msdn.microsoft.com/en-us/library/bb387165.aspx"&gt;EdmGen&lt;/a&gt;. Unfortunately, it does not give you access to some of the options supported by the framework. The new version of &lt;a href="http://t4toolbox.codeplex.com/"&gt;T4 Toolbox&lt;/a&gt; includes a code generator that encapsulates the functionality built into Entity Framework and makes it available in &lt;a href="http://www.olegsych.com/2007/12/text-template-transformation-toolkit/"&gt;T4&lt;/a&gt;-based code generation scripts. This code generator is based on the idea of using database modeling tools built into Visual Studio, which are easier to use and unlike Entity Framework’s own designer, are proven to work on the number of tables typically found in real-world databases. In the rest of this article we will review the process of using this code generator to illustrate its pros and cons.&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Getting Started&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;In order to follow this sample, you need to have Visual Studio 2008 or 2010, Standard Edition or higher, SQL Server Express 2005 or later, &lt;a href="http://t4toolbox.codeplex.com/"&gt;T4 Toolbox&lt;/a&gt; and &lt;a href="http://www.olegsych.com/2009/04/t4-editor-by-tangible-engineering"&gt;T4 Editor&lt;/a&gt; installed on your computer.&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Create a new C# or Visual Basic console application project. &lt;/li&gt;    &lt;li&gt;Add a new item to your project and select the &lt;i&gt;Code Generation&lt;/i&gt;-&amp;gt;&lt;i&gt;Entity Framework Database&lt;/i&gt; template in the &lt;i&gt;Add New Item &lt;/i&gt;dialog. &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&lt;a href="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/5126.clip_5F00_image003_5F00_4D73559D.gif"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="clip_image003" border="0" alt="clip_image003" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/6371.clip_5F00_image003_5F00_thumb_5F00_15C09B6D.gif" width="244" height="139" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Enter the desired database name and click &lt;i&gt;Add&lt;/i&gt;. &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;This template adds a new, empty SQL Express database to your project. Unfortunately, Visual Studio automatically displays the the Data Source Configuration Wizard whenever you add a .mdf file to a project. Normally, you would use it to create a data access layer with built-in visual designers. In this case, we have the entire data access layer generated automatically for us.&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Click &lt;i&gt;Cancel &lt;/i&gt;in the &lt;i&gt;Data Source Configuration Wizard.&lt;/i&gt;&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&lt;a href="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/2063.clip_5F00_image005_5F00_58333DA3.gif"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="clip_image005" border="0" alt="clip_image005" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/7444.clip_5F00_image005_5F00_thumb_5F00_5A03936A.gif" width="244" height="205" /&gt;&lt;/a&gt;&lt;a href="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/2148.clip_5F00_image007_5F00_753BEC6B.gif"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="clip_image007" border="0" alt="clip_image007" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/2158.clip_5F00_image007_5F00_thumb_5F00_652FAE65.gif" width="163" height="244" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Notice that a number of files have been added to your project, including a .mdf file (SQL database), a .ldf file (SQL log), a .tt file (code generator), a .cs/.vb file (entity classes and object context), a .Views.cs/.vb file (precompiled entity views), a .csdl file (conceptual model), a .ssdl file (storage model) and a .msl file (mapping model). If you are using Visual Basic, you will need to click “&lt;i&gt;Show All Files&lt;/i&gt;” button in solution explorer in order to see the files nested under .mdf and .tt.&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Database Modeling&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;Visual Studio includes a subset of database modeling functionality from SQL Server Management Studio, including database diagrams, table designers, key and relationship designers.&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/2063.clip_5F00_image009_5F00_44A86EB3.gif"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="clip_image009" border="0" alt="clip_image009" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/8422.clip_5F00_image009_5F00_thumb_5F00_5BD679E2.gif" width="225" height="244" /&gt;&lt;/a&gt;Double-click the .mdf file in &lt;i&gt;Solution Explorer &lt;/i&gt;(shown above)&lt;i&gt;.&lt;/i&gt; This will cause the database to be opened in &lt;i&gt;Server Explorer&lt;/i&gt; (shown on the left). &lt;/li&gt;    &lt;li&gt;Right-click &lt;i&gt;Database Diagrams&lt;/i&gt; in &lt;i&gt;Server Explorer&lt;/i&gt; and select &lt;i&gt;Add New Diagram&lt;/i&gt; from the context menu. &lt;/li&gt;    &lt;li&gt;The first time you add a diagram to a database, Visual Studio will prompts you to create database objects required for diagramming. Click Yes when prompted. &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Use the diagram to create a new database model.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.olegsych.com/wp-content/uploads/2009/12/image7.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="clip_image011" border="0" alt="clip_image011" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/3225.clip_5F00_image011_5F00_693C8CE8.gif" width="244" height="13" /&gt;&lt;/a&gt;&lt;a href="http://www.olegsych.com/wp-content/uploads/2009/12/image8.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="clip_image013" border="0" alt="clip_image013" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/5126.clip_5F00_image013_5F00_2906736E.gif" width="244" height="210" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/4721.clip_5F00_image015_5F00_6F836376.gif"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="clip_image015" border="0" alt="clip_image015" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/5126.clip_5F00_image015_5F00_thumb_5F00_2D7F84E6.gif" width="195" height="244" /&gt;&lt;/a&gt;Database diagrams allow you to quickly model tables and their relationships. You can use the &lt;i&gt;Properties Window&lt;/i&gt; of Visual Studio to configure individual tables and columns selected on the design surface. The toolbar and context menu provide access to commands that allow you to model keys, relationships, indexes, unique and check constraints, as well as customize the look of your diagram for display and print, add text annotations and more. Also, unlike with Entity Framework designer, you can create additional diagrams when the number of tables is too big to fit on a single diagram. This seemingly trivial feature is crucial for large database models.&lt;/p&gt;  &lt;p&gt;Having the model database included in your project has several important benefits. It is placed under source control with the rest of the files in your project, giving you the ability to go back to previous versions when necessary. Although it may seem excessive to check in an entire database in source control, the size of a .mdf file is comparable to the size of a similar database model stored in a Visio .vsd file or an Enterprise Architect .eap file. You can also use the database file itself to store any seed data you need and with “Copy to Output Directory” option turned on, the database deployment becomes a simple xcopy on &lt;a href="http://en.wikipedia.org/wiki/Greenfield_project"&gt;greenfield projects&lt;/a&gt;.&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Make sure to save changes you make in any database diagram or designers you open before you proceed to the next step of generating code. &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&lt;b&gt;Code Generation&lt;/b&gt;&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Double-click the .tt file in &lt;i&gt;Solution Explorer &lt;/i&gt;(shown above) to open it in the &lt;a href="http://www.olegsych.com/2009/04/t4-editor-by-tangible-engineering/"&gt;T4 Editor&lt;/a&gt;. &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&lt;b&gt;C#&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;#@ template language=“C#“ hostspecific=“True“ #&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;#@ output extension=“cs“ #&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;#@ include file=“T4Toolbox.tt“ #&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;#@ include file=“T4Toolbox\EntityFramework.tt“ #&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;#&lt;/p&gt;  &lt;p&gt;var generator = new EntityFrameworkGenerator();&lt;/p&gt;  &lt;p&gt;generator.DatabaseFile = “Database1.mdf”;&lt;/p&gt;  &lt;p&gt;generator.Run();&lt;/p&gt;  &lt;p&gt;#&amp;gt;&lt;/p&gt;  &lt;p&gt;&lt;b&gt;VB&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;#@ template language=“VB“ hostspecific=“True“ #&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;#@ output extension=“vb“ #&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;#@ include file=“T4Toolbox.tt“ #&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;#@ include file=“T4Toolbox\EntityFramework.tt“ #&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;#&lt;/p&gt;  &lt;p&gt;Dim generator As New EntityFrameworkGenerator()&lt;/p&gt;  &lt;p&gt;generator.DatabaseFile = “Database1.mdf”&lt;/p&gt;  &lt;p&gt;generator.LanguageOption = LanguageOption.GenerateVBCode&lt;/p&gt;  &lt;p&gt;generator.Run()&lt;/p&gt;  &lt;p&gt;#&amp;gt;&lt;/p&gt;  &lt;p&gt;This is a &lt;a href="http://www.olegsych.com/2007/12/text-template-transformation-toolkit/"&gt;T4&lt;/a&gt; code generation script that creates a new instance of &lt;i&gt;EntityFrameworkGenerator&lt;/i&gt;, configures its properties and uses it to generate all model and code files required for a ready-to-use data access layer based on Entity Framework. Note that this script is not directly associated with the database file in the Visual Studio project and has to be run manually.&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Right-click the .tt file in &lt;i&gt;Solution Explorer&lt;/i&gt; and select &lt;i&gt;Run Custom Tool&lt;/i&gt; from its context menu to trigger the code generation. &lt;/li&gt;    &lt;li&gt;Double-click the&amp;#160; generated .cs/.vb file in &lt;i&gt;Solution Explorer&lt;/i&gt; to open it in the Visual Studio editor. If you are using Visual Basic, you will need to click “&lt;i&gt;Show All Files&lt;/i&gt;” in the toolbar of &lt;i&gt;Solution Explorer&lt;/i&gt; in order to see this file. &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&lt;b&gt;C#&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.olegsych.com/wp-content/uploads/2009/12/image10.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="clip_image017" border="0" alt="clip_image017" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/3666.clip_5F00_image017_5F00_25F41579.gif" width="244" height="192" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;b&gt;VB&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.olegsych.com/wp-content/uploads/2009/12/image11.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="clip_image019" border="0" alt="clip_image019" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/7444.clip_5F00_image019_5F00_3A7964F7.gif" width="244" height="201" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;This generated file contains definitions of both entity classes and object context required to access the database using LINQ to Entities.&lt;/p&gt;  &lt;p&gt;Also note the other generated code file, in our example Database1.Views.cs/.vb. This file contains &lt;a href="http://blogs.msdn.com/adonet/archive/2008/02/04/exploring-the-performance-of-the-ado-net-entity-framework-part-1.aspx"&gt;pre-generated views&lt;/a&gt;, which significantly improve reduce the amount of time required to connect to a database using an Entity Framework object context for the first time. This can take tens of seconds even on a medium-size database with a hundred of tables. While this performance hit does not have a meaningful effect on applications in production due to Entity Framework caching the views on per-AppDomain basis, this delay is a significant problem for developers who need to recompile and restart the application frequently. The Entity Framework designer does not generate views automatically, causing much frustration for developers and, perhaps, being the main reason for Entity Frameworks reputation of having poor performance.&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Coding&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;At this point, you have everything you need to start coding against your new database using LINQ to Entities.&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Double-click Program.cs or Module.vb in &lt;i&gt;Solution Explorer&lt;/i&gt;. &lt;/li&gt;    &lt;li&gt;Enter the following code in the editor. &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&lt;b&gt;C#&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;using System;&lt;/p&gt;  &lt;p&gt;using System.Linq; &lt;/p&gt;  &lt;p&gt;namespace EfDalSampleCS&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;class Program&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;static void Main(string[] args)&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;var context = new Database1Entities();&lt;/p&gt;  &lt;p&gt;context.AddToProducts(new Product() { ProductName = “Internet Explorer”, UnitPrice = 0 });&lt;/p&gt;  &lt;p&gt;context.AddToProducts(new Product() { ProductName = “Windows 7 Ultimate”, UnitPrice = 319.99M });&lt;/p&gt;  &lt;p&gt;context.SaveChanges(); &lt;/p&gt;  &lt;p&gt;var products = from p in context.Products select p;&lt;/p&gt;  &lt;p&gt;foreach (var product in products)&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;Console.WriteLine(“{0} ({1})”, product.ProductName, product.UnitPrice);&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;} &lt;/p&gt;  &lt;p&gt;&lt;b&gt;VB&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;Imports System&lt;/p&gt;  &lt;p&gt;Imports System.Linq&lt;/p&gt;  &lt;p&gt;Imports EfDalSampleVB.EfDalSampleVB &lt;/p&gt;  &lt;p&gt;Module Module1&lt;/p&gt;  &lt;p&gt;Sub Main()&lt;/p&gt;  &lt;p&gt;Dim context As New Database1Entities&lt;/p&gt;  &lt;p&gt;context.AddToProducts(New Product() With {.ProductName = “Internet Explorer”, .UnitPrice = 0})&lt;/p&gt;  &lt;p&gt;context.AddToProducts(New Product() With {.ProductName = “Windows 7 Ultimate”, .UnitPrice = 319.99})&lt;/p&gt;  &lt;p&gt;context.SaveChanges() &lt;/p&gt;  &lt;p&gt;Dim products = From p In context.Products Select p&lt;/p&gt;  &lt;p&gt;For Each product In products&lt;/p&gt;  &lt;p&gt;Console.WriteLine(“{0} ({1})”, product.ProductName, product.UnitPrice)&lt;/p&gt;  &lt;p&gt;Next&lt;/p&gt;  &lt;p&gt;End Sub&lt;/p&gt;  &lt;p&gt;End Module&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Press F5 to run the program. You may want to set a breakpoint and observe execution of the program in Visual Studio debugger. &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;A couple of things are worth explaining. How does this code know which database to connect to? The answer lies in the default constructor of &lt;i&gt;Database1Entities&lt;/i&gt; class, which is generated to use a connection string with the same name. This connection string was automatically added to the configuration file when we added &lt;i&gt;Database1.mdf&lt;/i&gt; to our project.&lt;/p&gt;  &lt;p&gt;&amp;lt;?xml version=“1.0” encoding=“utf-8“?&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;configuration&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;connectionStrings&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;add name=“Database1Entities”&lt;/p&gt;  &lt;p&gt;connectionString=&lt;/p&gt;  &lt;p&gt;”&lt;/p&gt;  &lt;p&gt;metadata=res://*/Database1.csdl&lt;/p&gt;  &lt;p&gt;|res://*/Database1.ssdl&lt;/p&gt;  &lt;p&gt;|res://*/Database1.msl;&lt;/p&gt;  &lt;p&gt;provider=System.Data.SqlClient;&lt;/p&gt;  &lt;p&gt;provider connection string=&lt;/p&gt;  &lt;p&gt;‘&lt;/p&gt;  &lt;p&gt;Data Source=.\SQLEXPRESS;&lt;/p&gt;  &lt;p&gt;AttachDbFilename=|DataDirectory|\Database1.mdf;&lt;/p&gt;  &lt;p&gt;Integrated Security=True;&lt;/p&gt;  &lt;p&gt;User Instance=True&lt;/p&gt;  &lt;p&gt;‘&lt;/p&gt;  &lt;p&gt;”&lt;/p&gt;  &lt;p&gt;providerName=“System.Data.EntityClient” /&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;/connectionStrings&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;/configuration&amp;gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.olegsych.com/wp-content/uploads/2009/12/image12.png"&gt;&lt;/a&gt;&lt;a href="http://www.olegsych.com/wp-content/uploads/2009/12/image12.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="clip_image021" border="0" alt="clip_image021" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/4237.clip_5F00_image021_5F00_4EFEB475.gif" width="230" height="244" /&gt;&lt;/a&gt;&lt;a href="http://www.olegsych.com/wp-content/uploads/2009/12/image12.png"&gt;&lt;/a&gt;Metadata section of the connection string specifies that .csdl, .ssdl and .msl files are embedded as resources in the executable. Provider section of the connection string instructs Entity Framework to use ADO.NET SQL Client to connect to the database. The provider connection string section contains the traditional connection string and indicates that SQL Server Express edition will be used to automatically attach the database file located in &lt;i&gt;DataDirectory&lt;/i&gt;. For windows applications (such as the console app we have here), &lt;i&gt;DataDirectory&lt;/i&gt; token refers to the directory where the&amp;#160; executable is located. Our database file is copied to the output directory because the “Copy to Output Directory” option was set to “Copy Always” for the .mdf file in our project.&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Customizing the list of database objects exposed by DAL&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;You may have noticed that among the generated entity classes, we also have &lt;i&gt;sysdiagrams&lt;/i&gt;, which was actually the table created by SQL Server when we added the first diagram to our database. Unless you are planning to access this table from your application, it would be best to remove it from the data access layer. You can can do that by adding a &lt;i&gt;filter&lt;/i&gt; to the code generator.&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Add the following code to the .tt file before &lt;i&gt;generator.Run()&lt;/i&gt; method is called. &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&lt;b&gt;C#&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;generator.Filters.Add(&lt;/p&gt;  &lt;p&gt;new EntityStoreSchemaFilterEntry(&lt;/p&gt;  &lt;p&gt;null, // catalog&lt;/p&gt;  &lt;p&gt;null, // schema&lt;/p&gt;  &lt;p&gt;“sys%”, // name&lt;/p&gt;  &lt;p&gt;EntityStoreSchemaFilterObjectTypes.Table,&lt;/p&gt;  &lt;p&gt;EntityStoreSchemaFilterEffect.Exclude));&lt;/p&gt;  &lt;p&gt;&lt;b&gt;VB&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;generator.Filters.Add( _&lt;/p&gt;  &lt;p&gt;New EntityStoreSchemaFilterEntry( _&lt;/p&gt;  &lt;p&gt;Nothing, _&lt;/p&gt;  &lt;p&gt;Nothing, _&lt;/p&gt;  &lt;p&gt;“sys%”, _&lt;/p&gt;  &lt;p&gt;EntityStoreSchemaFilterObjectTypes.Table, _&lt;/p&gt;  &lt;p&gt;EntityStoreSchemaFilterEffect.Exclude))&lt;/p&gt;  &lt;p&gt;This code creates a filter entry object that indicates that all tables whose name starts with &lt;i&gt;“sys”&lt;/i&gt; should be excluded from the generated DAL. &lt;i&gt;EntityFrameworkGenerator&lt;/i&gt; class contains a property called &lt;i&gt;Filters&lt;/i&gt; to which you can add one or more filter entries and make sure that only appropriate database objects are accessible through the DAL. For complete details, please refer to &lt;a href="http://msdn.microsoft.com/en-us/library/system.data.entity.design.entitystoreschemafilterentry.aspx"&gt;EntityStoreSchemaFilterEntry&lt;/a&gt;, &lt;a href="http://msdn.microsoft.com/en-us/library/system.data.entity.design.entitystoreschemafilterobjecttypes.aspx"&gt;EntityStoreSchemaFilterObjectTypes&lt;/a&gt; and &lt;a href="http://msdn.microsoft.com/en-us/library/system.data.entity.design.entitystoreschemafiltereffect.aspx"&gt;EntityStoreSchemaFilterEffect&lt;/a&gt; on MSDN.&lt;/p&gt;  &lt;p&gt;Unfortunately, not all of the possible combinations of object types and filter effects are supported by the underlying Entity Framework generator. For example, creating a filter entry to include functions in the DAL has no effect because the functions are only automatically generated in the storage model (.ssdl) and not in the conceptual model (.csdl). In other words, you cannot access stored procedures using the DAL produced by this code generator in its current version.&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Customizing pluralization of entity class names and set names&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;Entity Framework 4.0 in Visual Studio 2010 provides an option to automatically convert table names to singular form in names of entity classes and to plural form in names of entity set properties. Without this automatic conversion, both entity name and set name would be either in plural form or singular form, depending on the naming convention you use in your database model. This poses a significant limitation in Entity Framework 3.5 in Visual Studio 2008, making the resulting DAL more confusing. A &lt;a href="http://blogs.msdn.com/efdesign/archive/2008/12/02/pluralization.aspx"&gt;complete discussion of pluralization&lt;/a&gt; by the Entity Framework team is available on their blog.&lt;/p&gt;  &lt;p&gt;The code generator in T4 Toolbox has the pluralization turned on by default in Visual Studio 2010. If you need to generate the DAL without pluralization, perhaps for compatibility reasons, you can turn this option off by adding the following line to the .tt file before &lt;i&gt;generator.Run()&lt;/i&gt; method is called.&lt;/p&gt;  &lt;p&gt;&lt;b&gt;C#&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;generator.Pluralize = false;&lt;/p&gt;  &lt;p&gt;&lt;b&gt;VB&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;generator.Pluralize = False&lt;/p&gt;  &lt;p&gt;This option is not available in Visual Studio 2008 because the underlying code generator in Entity Framework does not support it.&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Customizing generation of foreign key properties&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;Entity Framework 4.0 in Visual Studio 2010 also provides an option to generate and use foreign key properties (such as Order.ProductId) in addition to navigation properties (such as Order.Product). Detailed discussion of &lt;a href="http://blogs.msdn.com/efdesign/archive/2009/03/16/foreign-keys-in-the-entity-framework.aspx"&gt;foreign key properties&lt;/a&gt; is also available on the Entity Framework team blog.&lt;/p&gt;  &lt;p&gt;The code generator in T4 Toolbox offers an option to generate foreign key properties, however you need to turn it on explicitly, by adding the following line to the .tt file before &lt;i&gt;generator.Run()&lt;/i&gt; method is called.&lt;/p&gt;  &lt;p&gt;&lt;b&gt;C#&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;generator.GenerateForeignKeyProperties = true;&lt;/p&gt;  &lt;p&gt;&lt;b&gt;VB&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;generator.GenerateForeignKeyProperties = True&lt;/p&gt;  &lt;p&gt;This option is not available in Visual Studio 2008 because the underlying code generator in Entity Framework does not support it.&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Customizing location of the model database&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;When storing the model database under source control is not desirable on your project, you can change the code generator to use a standalone database as the model.&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Change the .tt file to specify a connection string instead of the database file. &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&lt;b&gt;C#&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;#@ template language=“C#“ hostspecific=“True“ #&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;#@ output extension=“cs“ #&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;#@ include file=“T4Toolbox.tt“ #&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;#@ include file=“T4Toolbox\EntityFramework.tt“ #&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;#&lt;/p&gt;  &lt;p&gt;EntityFrameworkGenerator generator = new EntityFrameworkGenerator();&lt;/p&gt;  &lt;p&gt;generator.ConnectionString = “Server=.;Database=Northwind;Integrated Security=True”;&lt;/p&gt;  &lt;p&gt;generator.Run();&lt;/p&gt;  &lt;p&gt;#&amp;gt;&lt;/p&gt;  &lt;p&gt;&lt;b&gt;VB&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;#@ template language=“VB“ hostspecific=“True“ #&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;#@ output extension=“vb“ #&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;#@ include file=“T4Toolbox.tt“ #&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;#@ include file=“T4Toolbox\EntityFramework.tt“ #&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;#&lt;/p&gt;  &lt;p&gt;Dim generator As New EntityFrameworkGenerator()&lt;/p&gt;  &lt;p&gt;generator.ConnectionString = “Server=.;Database=Northwind;Integrated Security=True”&lt;/p&gt;  &lt;p&gt;generator.LanguageOption = LanguageOption.GenerateVBCode&lt;/p&gt;  &lt;p&gt;generator.Run()&lt;/p&gt;  &lt;p&gt;#&amp;gt;&lt;/p&gt;  &lt;p&gt;When you save the modified .tt file, the DAL will be regenerated based on the metadata in the database you specified in the connection string. By default, database name determines the name of the generated object context class. Changing the name of the database from &lt;i&gt;Database1&lt;/i&gt; to &lt;i&gt;Northwind&lt;/i&gt; will change the name of the context class from &lt;i&gt;Database1Entities &lt;/i&gt;to &lt;i&gt;NorthwindEntities&lt;/i&gt;.&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Rename the .tt file to match the name of the database (&lt;i&gt;Northwind.tt&lt;/i&gt; in our example)&lt;i&gt;.&lt;/i&gt;&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Although this is not required, renaming the code generation script will make the names of the generated .csdl, .ssdl and .msl files match the name of the database and make the solution easier to understand.&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Update the configuration file to match the changes made in generated code. &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&amp;lt;?xml version=“1.0” encoding=“utf-8“?&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;configuration&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;connectionStrings&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;add name=“NorthwindEntities”&lt;/p&gt;  &lt;p&gt;connectionString=&lt;/p&gt;  &lt;p&gt;”&lt;/p&gt;  &lt;p&gt;metadata=res://*/Northwind.csdl&lt;/p&gt;  &lt;p&gt;|res://*/Northwind.ssdl&lt;/p&gt;  &lt;p&gt;|res://*/Northwind.msl;&lt;/p&gt;  &lt;p&gt;provider=System.Data.SqlClient;&lt;/p&gt;  &lt;p&gt;provider connection string=&lt;/p&gt;  &lt;p&gt;‘&lt;/p&gt;  &lt;p&gt;Server=.;&lt;/p&gt;  &lt;p&gt;Database=Northwind;&lt;/p&gt;  &lt;p&gt;Integrated Security=True;&lt;/p&gt;  &lt;p&gt;‘&lt;/p&gt;  &lt;p&gt;”&lt;/p&gt;  &lt;p&gt;providerName=“System.Data.EntityClient” /&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;/connectionStrings&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;/configuration&amp;gt;&lt;/p&gt;  &lt;p&gt;In particular, the name of the connection string has to match the new name of the object context class (&lt;i&gt;NorthwindEntities&lt;/i&gt; in this example); file names in the metadata section of the connection string have to match the names of the generated model files (&lt;i&gt;Northwind.csdl&lt;/i&gt;, &lt;i&gt;Northwind.ssdl &lt;/i&gt;and &lt;i&gt;Northwind.msl&lt;/i&gt; in this example); and finally, the provider connection string section of the connection string has to point to the actual database in your current environment.&lt;/p&gt;  &lt;p&gt;Note that database connection string is present in both .tt and .config files. In this example, the same Northwind database on local SQL server is used during both code generation and execution. You may want to use different databases for these purposes, perhaps an empty local database for code generation and a shared database for development and testing. In that case, make sure to use appropriate connection strings in the .tt and .config files.&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Other customization options&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;Additional details about customization options are available in the T4 Toolbox documentation installed as part of the Visual Studio 2008 help collection. If you have it installed, you can click &lt;a&gt;here&lt;/a&gt; to open the list of properties available for you to use in the code generation script.&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Conclusion&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;ADO.NET Entity Framework allows you to access database in object-oriented manner at the cost of additional effort required to maintain conceptual, storage and mapping model. While sounding good in theory, solving the object-relational impedance mismatch in practice typically increases the cost of information systems due to additional knowledge, experience and effort it requires with tools available today. By implementing an automatically-generated, modern, strongly-typed, LINQ-enabled data access layer based on Entity Framework, we can improve developer productivity and reduce the system development cost without introducing the overhead and complexity of fully featured object-relational mapping. Unlike the tools built into Entity Framework, the database modeling functionality in Visual Studio and the code generator described in this article allow you to use Entity Framework effectively with more than just a few dozen tables. Unfortunately, due to limitations in the current version of Entity Framework, the solution described in this article does not allow accessing stored procedures and functions through the automatically generated DAL, making it inferior compared to a similar DAL based on LINQ to SQL today.&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Download&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.olegsych.com/wp-content/uploads/2009/12/efdalsample.zip"&gt;Sample source code&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://community.icburner.com/aggbug.aspx?PostID=2000" width="1" height="1"&gt;</description><category domain="http://community.icburner.com/blogs/vs2010tests/archive/tags/Entity+Framework/default.aspx">Entity Framework</category><category domain="http://community.icburner.com/blogs/vs2010tests/archive/tags/Entity+Framework+4.0/default.aspx">Entity Framework 4.0</category></item><item><title>T4 Templates: A Quick-Start Guide for ASP.NET MVC Developers</title><link>http://community.icburner.com/blogs/vs2010tests/archive/2009/12/24/t4-templates-a-quick-start-guide-for-asp-net-mvc-developers.aspx</link><pubDate>Thu, 24 Dec 2009 10:35:05 GMT</pubDate><guid isPermaLink="false">7695cfbe-8499-488a-81cc-9a443df3b4ce:1999</guid><dc:creator>革命</dc:creator><slash:comments>0</slash:comments><description>&lt;h3&gt;&amp;#160;&lt;/h3&gt;  &lt;p&gt;As mentioned in our &lt;a href="http://blogs.msdn.com/webdevtools/archive/2009/01/27/overview-of-mvc-tools-features.aspx"&gt;recent blog post&lt;/a&gt; on the &lt;a href="http://go.microsoft.com/fwlink/?LinkID=141184&amp;amp;clcid=0x409"&gt;ASP.NET MVC Release Candidate&lt;/a&gt;, our code-generation features (namely, Add Controller and Add View) now use the T4 (Text Template Transformation Toolkit) templating technology behind the scenes.&amp;#160; Because users can customize the templates to a great extent, we wanted to make a post to bring everyone up to speed on T4.&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Template Locations and Template Override&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;The Add Controller and Add View dialogs both perform code generation that use T4 templates behind the scenes.&amp;#160; These templates can be modified to customize the generated code from these tools.&amp;#160; You can find the templates at the following location: [Visual Studio Install Directory]\Common7\IDE\ItemTemplates\[CSharp | VisualBasic]\Web\MVC\CodeTemplates\&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/webdevtools/WindowsLiveWriter/T4TemplatesAQuickStartGuide_D21E/TemplatesLocation_4.jpg"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="clip_image001" border="0" alt="clip_image001" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/2642.clip_5F00_image001_5F00_52BA7864.jpg" width="244" height="64" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;You can also copy the ‘CodeTemplates’ folder into the root of your project to be able to override the templates at the above location and customize the templates on a per-project basis (alternatively, just create a folder named ‘CodeTemplates’ and under that create a folder named ‘AddController’ or ‘AddView’).&amp;#160; Note that you can choose to override some templates but not others if you so wish – the dialogs will respect the precedence of what is in your project properly.&amp;#160; Also keep in mind that for the Add View dialog, you can add your own .tt files either at the global location or in your project and have them automatically populated in the View Content drop-down in the dialog.&lt;/p&gt;  &lt;p&gt;Please note that when you copy the above folder (really, any time you add a .tt file) into the project, you will see warnings as follows:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/webdevtools/WindowsLiveWriter/T4TemplatesAQuickStartGuide_D21E/TemplateExecutionWarning_2.jpg"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="clip_image002" border="0" alt="clip_image002" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/2577.clip_5F00_image002_5F00_673FC7E2.jpg" width="244" height="92" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Hit ‘Cancel’ so that you don’t run the T4 template (if you are adding multiple .tt files like when you copy the ‘CodeTemplates’ folder, you will have to hit ‘Cancel’ each time).&amp;#160; This happens because as soon as the project sees a .tt file, a property on the file called ‘CustomTool’ will get set to ‘TextTemplatingFileGenerator’&amp;#160; What this is telling Visual Studio to do is to use the default T4 host to execute the template and create a new file (nested underneath the template) based on what’s in the template.&lt;/p&gt;  &lt;p&gt;The generator can be a great way to have one-off file generation based on a template, or to simply play around with T4 – however, because Add View and Add Controller templates have code in them that rely on a custom template host (as you’ll see later), executing these templates with the default generator will simply generate errors.&amp;#160; Go ahead and clear out the Custom Tool property to just be empty after copying the templates into your project.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/webdevtools/WindowsLiveWriter/T4TemplatesAQuickStartGuide_D21E/CustomToolProperty_2.jpg"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="clip_image003" border="0" alt="clip_image003" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/6378.clip_5F00_image003_5F00_7BC51760.jpg" width="244" height="135" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;i&gt;Note: If you want to get rid of the mapping that automatically sets the Custom Tool on .tt files, you can do so through the registry – please note that if you want to restore these registry keys to their default values, you can perform a Repair from the Visual Studio installer, or add the entries back manually.&amp;#160; Start up the registry editor (Start –&amp;gt; Run –&amp;gt; ‘regedit’) and navigate to one of the following locations depending on whether you are using a 32-bit or 64-bit install of Windows:&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;&lt;i&gt;32-bit: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\9.0\Generators&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;&lt;i&gt;64-bit: HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\9.0\Generators&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/webdevtools/WindowsLiveWriter/T4TemplatesAQuickStartGuide_D21E/T4Registry_2.jpg"&gt;&lt;i&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="clip_image004" border="0" alt="clip_image004" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/0820.clip_5F00_image004_5F00_37187D1F.jpg" width="168" height="244" /&gt;&lt;/i&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;i&gt;Expand each of the nodes directly under ‘Generators’ and look for any entries named ‘.tt’.&amp;#160; Set the registry value named ‘(Default)’ to be empty.&amp;#160; That’s it!&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/webdevtools/WindowsLiveWriter/T4TemplatesAQuickStartGuide_D21E/T4RegistryEdit_2.jpg"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="clip_image005" border="0" alt="clip_image005" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/6864.clip_5F00_image005_5F00_1D4446F0.jpg" width="244" height="135" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;If you want to override the global templates but don’t want to copy a folder named ‘CodeTemplates’ into your project (since you already have a folder by that name presumably), you can change the name of the folder Add Controller and Add View look at through a registry key.&amp;#160; Start up the registry editor (Start –&amp;gt; Run –&amp;gt; ‘regedit’) and navigate to one of the following locations depending on whether you are using a 32-bit or 64-bit install of Windows:&lt;/p&gt;  &lt;p&gt;32-bit: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\9.0\MVC\CodeTemplates&lt;/p&gt;  &lt;p&gt;64-bit: HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\9.0\MVC\CodeTemplates&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/webdevtools/WindowsLiveWriter/T4TemplatesAQuickStartGuide_D21E/T4OverrideRegistry_2.jpg"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="clip_image006" border="0" alt="clip_image006" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/2642.clip_5F00_image006_5F00_26A00C24.jpg" width="227" height="79" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Change the value for ‘OverrideDir’ to what you want the tooling to look for in your project.&amp;#160; Please note that under this folder you will still have to maintain the same hierarchy as before, with a folder named ‘AddController’ and/or a folder named ‘AddView’.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/webdevtools/WindowsLiveWriter/T4TemplatesAQuickStartGuide_D21E/T4OverrideRegistryEdit_2.jpg"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="clip_image007" border="0" alt="clip_image007" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/5710.clip_5F00_image007_5F00_3B255BA2.jpg" width="244" height="150" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Editing T4 Templates&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;If you open a .tt file inside Visual Studio, you may notice they look a bit flat – like a wall of black text.&amp;#160; We highly highly recommend you download &lt;a href="http://www.t4editor.net/"&gt;T4 Editor&lt;/a&gt;, an add-on to Visual Studio made by &lt;a href="http://www.clariusconsulting.net/"&gt;Clarius Consulting&lt;/a&gt;, to provide you with syntax highlighting and some basic T4 statement completion.&amp;#160; They have a free version called the ‘Community Edition’, as well as a much more powerful ‘Professional Edition’ – check out the &lt;a href="http://www.t4editor.net/features.html"&gt;feature comparison&lt;/a&gt; if you are interested.&amp;#160; This add-on really makes a big difference in template authoring, as you can see below.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/webdevtools/WindowsLiveWriter/T4TemplatesAQuickStartGuide_D21E/T4EditingWithoutClarius_2.jpg"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="clip_image008" border="0" alt="clip_image008" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/4705.clip_5F00_image008_5F00_1A9E1BF0.jpg" width="244" height="176" /&gt;&lt;/a&gt;&lt;a href="http://blogs.msdn.com/blogfiles/webdevtools/WindowsLiveWriter/T4TemplatesAQuickStartGuide_D21E/T4EditingWithClarius_2.jpg"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="clip_image009" border="0" alt="clip_image009" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/8446.clip_5F00_image009_5F00_4ED24536.jpg" width="244" height="184" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Anatomy of a T4 Template&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;The easiest way to get started with editing the templates yourself is to see how our default templates work.&amp;#160; To that end, we’re going to go through some of the pieces of the ‘Create’ template (Create.tt) for Add View.&amp;#160; Let’s start at the top:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/webdevtools/WindowsLiveWriter/T4TemplatesAQuickStartGuide_D21E/CreateTemplate1_4.jpg"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="clip_image010" border="0" alt="clip_image010" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/2158.clip_5F00_image010_5F00_25CA36EB.jpg" width="244" height="43" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;These four lines are all &lt;i&gt;directives&lt;/i&gt;.&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;The first line is the &lt;i&gt;template directive&lt;/i&gt;, and its main job is to tell the T4 engine what language the template itself uses.&amp;#160; When we say the template’s language, we don’t mean the language in which the output is written, but rather the template’s control code (for example, your template might include an &lt;i&gt;if-else&lt;/i&gt; statement to conditionally output some line of text).&amp;#160; The ‘HostSpecific’ attribute has to be set to ‘True’ to work with Add View or Add Controller, because otherwise the template cannot access the information the Add Controller and Add View dialogs want to provide them (things like the Type to which a strongly-typed view is bound etc) &lt;/li&gt;    &lt;li&gt;The next line is the &lt;i&gt;output directive&lt;/i&gt;, and it simply sets the default extension for the template’s output file by informing the template host – this isn’t particularly relevant to MVC Tools since depending on the situation the default extension may be ignored (for example, if we are dealing with a partial view, where the extension should be .ascx) &lt;/li&gt;    &lt;li&gt;The next couple lines are both &lt;i&gt;import directives&lt;/i&gt;, and they are like ‘using’ statements in C# or ‘Imports’ statements in VB.&amp;#160; If your template’s code uses any classes in its code, you will need to import them here.&lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;You can find more documentation on T4 directives here: &lt;a href="http://msdn.microsoft.com/en-us/library/bb126421.aspx"&gt;http://msdn.microsoft.com/en-us/library/bb126421.aspx&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Moving down just a bit, you will notice the following line:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/webdevtools/WindowsLiveWriter/T4TemplatesAQuickStartGuide_D21E/CreateTemplate2_2.jpg"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="clip_image011" border="0" alt="clip_image011" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/5314.clip_5F00_image011_5F00_0C6233B1.jpg" width="244" height="15" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;On this line we are creating a new variable named ‘mvcHost’, and assigning it to a casted version of a property named ‘Host’.&amp;#160; The ‘Host’ property is something provided to the template automatically because we set the ‘HostSpecific’ attribute to ‘True’ in the template directive above.&amp;#160; The MVC Tools provide a custom host, so as to be able to pass information to the templates that are not available outside of the tools.&amp;#160; To access the properties provided on our host class, the ‘Host’ property needs to be casted to our host type, which is ‘MvcTextTemplateHost’.&lt;/p&gt;  &lt;p&gt;How is this variable used?&amp;#160; It is actually quite straightforward:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/webdevtools/WindowsLiveWriter/T4TemplatesAQuickStartGuide_D21E/CreateTemplate3_2.jpg"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="clip_image012" border="0" alt="clip_image012" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/3644.clip_5F00_image012_5F00_4C2C1A36.jpg" width="244" height="125" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;The first thing to notice is that there is code enclosed within ‘&amp;lt;#’ and ‘#&amp;gt;’ tags.&amp;#160; These tags are called &lt;i&gt;statement blocks&lt;/i&gt; and are used to enclose control code.&amp;#160; Your template may want to conditionally output certain chunks of text into the output file and keep other chunks from being outputted.&amp;#160; Above, we have an &lt;i&gt;if&lt;/i&gt; statement (written in C# since our template’s language was set to C# in the template directive) that opens a curly brace.&amp;#160; This &lt;i&gt;if&lt;/i&gt; statement’s closing curly brace shows up a few lines below on Line 17, in a different statement block.&amp;#160; Note that this particular &lt;i&gt;if&lt;/i&gt; statement is accessing a property on the host called ‘IsViewUserControl’, which tells the template if the user chose to go with a partial view.&lt;/p&gt;  &lt;p&gt;All the text outside of blocks in a template are actual chunks of text that are outputted to the final file.&amp;#160; In the screenshot above, Line 14’s text is outside of any blocks and is thus part of the output – however, it will be placed into the output file only if the &lt;i&gt;if&lt;/i&gt; statement on Line 12 evaluates to ‘true’.&lt;/p&gt;  &lt;p&gt;You can learn more about T4 statement blocks here: &lt;a href="http://msdn.microsoft.com/en-us/library/bb126509.aspx"&gt;http://msdn.microsoft.com/en-us/library/bb126509.aspx&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;The easiest way to think of the control code in a T4 template is by sewing it together in your head into one big program.&amp;#160; The variable we declared previously on line 6 can be used in the T4 control code that follows it – and each of these if-else branches conditionally adds some text (shown in gray) to the outputted file.&amp;#160; The if-else statements above are checking some properties exposed by our template host to the Add View templates.&lt;/p&gt;  &lt;p&gt;Moving a bit further down, we see a curious statement block as follows:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/webdevtools/WindowsLiveWriter/T4TemplatesAQuickStartGuide_D21E/CreateTemplate4_4.jpg"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="clip_image013" border="0" alt="clip_image013" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/6303.clip_5F00_image013_5F00_1C710268.jpg" width="244" height="44" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;We declare a variable called ‘properties’ of type ‘List&amp;lt;string&amp;gt;’.&amp;#160; How are we able to use the List type in our T4 code?&amp;#160; It is because of this import directive we saw at the top of the template:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/webdevtools/WindowsLiveWriter/T4TemplatesAQuickStartGuide_D21E/CreateTemplate5_2.jpg"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="clip_image014" border="0" alt="clip_image014" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/4721.clip_5F00_image014_5F00_3C1FDC30.jpg" width="244" height="16" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Line 56 then calls a method called ‘FilterProperties’ – but where is this method located?&amp;#160; It is actually defined near the bottom of the template:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/webdevtools/WindowsLiveWriter/T4TemplatesAQuickStartGuide_D21E/CreateTemplate6_2.jpg"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="clip_image015" border="0" alt="clip_image015" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/1104.clip_5F00_image015_5F00_14E592FB.jpg" width="244" height="58" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;If you look carefully, unlike statement blocks, this block of code begins with ‘&amp;lt;#+’.&amp;#160; This is known as a &lt;i&gt;class feature blocks&lt;/i&gt;, and they work like this: T4 takes all the class features in your template and adds them to the class that is compiled from your template behind the scenes.&amp;#160; This isn’t just limited to methods, but also things like properties (anything that would normally go under a class).&amp;#160; Like a member of a class in a regular code file, these now become accessible to the rest of your template’s code.&lt;/p&gt;  &lt;p&gt;Read more about class feature blocks here: &lt;a href="http://msdn.microsoft.com/en-us/library/bb126541.aspx"&gt;http://msdn.microsoft.com/en-us/library/bb126541.aspx&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Our default templates use the ‘FilterProperties’ method from the above screenshot to by default output markup only for some properties in the type – namely ones that are public and would also be displayed in the designer by things like GridView.&amp;#160; This logic is identical to what you would get from calling the &lt;a href="http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.isbindabletype.aspx"&gt;GridView.IsBindableType&lt;/a&gt; method.&lt;/p&gt;  &lt;p&gt;The ‘IsBindableType’ method called on Line 136 is defined a bit further down in the template:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/webdevtools/WindowsLiveWriter/T4TemplatesAQuickStartGuide_D21E/CreateTemplate7_2.jpg"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="clip_image016" border="0" alt="clip_image016" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/2063.clip_5F00_image016_5F00_4985EF36.jpg" width="244" height="75" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;If you wanted to change which properties our templates filter out, you can modify either of these methods to your liking.&lt;/p&gt;  &lt;p&gt;Lastly, have a look at Line 65 below:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/webdevtools/WindowsLiveWriter/T4TemplatesAQuickStartGuide_D21E/CreateTemplate8_2.jpg"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="clip_image017" border="0" alt="clip_image017" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/2161.clip_5F00_image017_5F00_17221BB7.jpg" width="244" height="93" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Here, we have a new construct that begins with ‘&amp;lt;#=’.&amp;#160; This is called an &lt;i&gt;expression block&lt;/i&gt; and it is used to insert values from T4 code into the outputted text.&amp;#160; As you can see above, we have a foreach loop that is iterating properties and defines a variable local to the loop called ‘propertyName’.&amp;#160; Because we want to output a &amp;lt;th&amp;gt; tag for each property name, we use an expression block referencing that variable.&lt;/p&gt;  &lt;p&gt;You can find more about expression blocks here: &lt;a href="http://msdn.microsoft.com/en-us/library/bb126508.aspx"&gt;http://msdn.microsoft.com/en-us/library/bb126508.aspx&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;As you can see, the various ways through which you can selectively output text in a T4 template make T4 a very powerful tool in getting the productivity of automatic code-generation with the flexibility of customized output.&lt;/p&gt;  &lt;p&gt;&lt;b&gt;MVC Tools T4 Host Properties&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;The Add Controller and Add View dialogs each expose different properties to templates through the template host, as demonstrated above in our breakdown of the Create template.&amp;#160; Here is the full list of available properties exposed by our template host, for your template to use (&lt;i&gt;Note: The exact names of these properties may change between the RC and the final version&lt;/i&gt;):&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Add Controller:&lt;/b&gt;    &lt;table border="1" cellspacing="0" cellpadding="0"&gt;&lt;tbody&gt;       &lt;tr&gt;         &lt;td valign="top" width="300"&gt;           &lt;p&gt;&lt;b&gt;Property Name&lt;/b&gt;&lt;/p&gt;         &lt;/td&gt;          &lt;td valign="top" width="299"&gt;           &lt;p&gt;&lt;b&gt;Type&lt;/b&gt;&lt;/p&gt;         &lt;/td&gt;          &lt;td valign="top" width="299"&gt;           &lt;p&gt;&lt;b&gt;Description&lt;/b&gt;&lt;/p&gt;         &lt;/td&gt;       &lt;/tr&gt;        &lt;tr&gt;         &lt;td valign="top" width="300"&gt;           &lt;p&gt;ItemName&lt;/p&gt;         &lt;/td&gt;          &lt;td valign="top" width="299"&gt;           &lt;p&gt;System.String&lt;/p&gt;         &lt;/td&gt;          &lt;td valign="top" width="299"&gt;           &lt;p&gt;The name of the Controller class, including the ‘Controller’ suffix&lt;/p&gt;         &lt;/td&gt;       &lt;/tr&gt;        &lt;tr&gt;         &lt;td valign="top" width="300"&gt;           &lt;p&gt;NameSpace&lt;/p&gt;         &lt;/td&gt;          &lt;td valign="top" width="299"&gt;           &lt;p&gt;System.String&lt;/p&gt;         &lt;/td&gt;          &lt;td valign="top" width="299"&gt;           &lt;p&gt;The namespace into which the Controller is being generated&lt;/p&gt;         &lt;/td&gt;       &lt;/tr&gt;        &lt;tr&gt;         &lt;td valign="top" width="300"&gt;           &lt;p&gt;ExtraActionMethods&lt;/p&gt;         &lt;/td&gt;          &lt;td valign="top" width="299"&gt;           &lt;p&gt;System.Boolean&lt;/p&gt;         &lt;/td&gt;          &lt;td valign="top" width="299"&gt;           &lt;p&gt;Indicates whether or not the user checked the option in the Add Controller dialog to get extra action methods&lt;/p&gt;         &lt;/td&gt;       &lt;/tr&gt;        &lt;tr&gt;         &lt;td valign="top" width="300"&gt;           &lt;p&gt;ControllerRootName&lt;/p&gt;         &lt;/td&gt;          &lt;td valign="top" width="299"&gt;           &lt;p&gt;System.String&lt;/p&gt;         &lt;/td&gt;          &lt;td valign="top" width="299"&gt;           &lt;p&gt;The name of the controller class without the ‘Controller’ suffix&lt;/p&gt;         &lt;/td&gt;       &lt;/tr&gt;     &lt;/tbody&gt;&lt;/table&gt; &lt;/p&gt;  &lt;p&gt;&lt;b&gt;Add View:&lt;/b&gt;    &lt;table border="1" cellspacing="0" cellpadding="0"&gt;&lt;tbody&gt;       &lt;tr&gt;         &lt;td valign="top" width="298"&gt;           &lt;p&gt;&lt;b&gt;Property Name&lt;/b&gt;&lt;/p&gt;         &lt;/td&gt;          &lt;td valign="top" width="305"&gt;           &lt;p&gt;&lt;b&gt;Type&lt;/b&gt;&lt;/p&gt;         &lt;/td&gt;          &lt;td valign="top" width="293"&gt;           &lt;p&gt;&lt;b&gt;Description&lt;/b&gt;&lt;/p&gt;         &lt;/td&gt;       &lt;/tr&gt;        &lt;tr&gt;         &lt;td valign="top" width="296"&gt;           &lt;p&gt;ItemName&lt;/p&gt;         &lt;/td&gt;          &lt;td valign="top" width="309"&gt;           &lt;p&gt;System.String&lt;/p&gt;         &lt;/td&gt;          &lt;td valign="top" width="291"&gt;           &lt;p&gt;The name of the view (without extension), as typed in the Add View dialog&lt;/p&gt;         &lt;/td&gt;       &lt;/tr&gt;        &lt;tr&gt;         &lt;td valign="top" width="295"&gt;           &lt;p&gt;NameSpace&lt;/p&gt;         &lt;/td&gt;          &lt;td valign="top" width="312"&gt;           &lt;p&gt;System.String&lt;/p&gt;         &lt;/td&gt;          &lt;td valign="top" width="289"&gt;           &lt;p&gt;The default namespace of the view’s parent folder&lt;/p&gt;         &lt;/td&gt;       &lt;/tr&gt;        &lt;tr&gt;         &lt;td valign="top" width="294"&gt;           &lt;p&gt;IsViewUserControl&lt;/p&gt;         &lt;/td&gt;          &lt;td valign="top" width="315"&gt;           &lt;p&gt;System.Boolean&lt;/p&gt;         &lt;/td&gt;          &lt;td valign="top" width="288"&gt;           &lt;p&gt;Evaluates to true if the user chose a partial view in the Add View dialog&lt;/p&gt;         &lt;/td&gt;       &lt;/tr&gt;        &lt;tr&gt;         &lt;td valign="top" width="293"&gt;           &lt;p&gt;IsViewContentPage&lt;/p&gt;         &lt;/td&gt;          &lt;td valign="top" width="317"&gt;           &lt;p&gt;System.Boolean&lt;/p&gt;         &lt;/td&gt;          &lt;td valign="top" width="287"&gt;           &lt;p&gt;Evaluates to true if the user is creating a view with a master page&lt;/p&gt;         &lt;/td&gt;       &lt;/tr&gt;        &lt;tr&gt;         &lt;td valign="top" width="292"&gt;           &lt;p&gt;IsViewPage&lt;/p&gt;         &lt;/td&gt;          &lt;td valign="top" width="319"&gt;           &lt;p&gt;System.Boolean&lt;/p&gt;         &lt;/td&gt;          &lt;td valign="top" width="286"&gt;           &lt;p&gt;Evaluates to true if the user is creating a regular view page&lt;/p&gt;         &lt;/td&gt;       &lt;/tr&gt;        &lt;tr&gt;         &lt;td valign="top" width="292"&gt;           &lt;p&gt;MasterPage&lt;/p&gt;         &lt;/td&gt;          &lt;td valign="top" width="320"&gt;           &lt;p&gt;System.String&lt;/p&gt;         &lt;/td&gt;          &lt;td valign="top" width="286"&gt;           &lt;p&gt;Path to the master page the user chose in the dialog (to be used only when IsViewContentPage is true)&lt;/p&gt;         &lt;/td&gt;       &lt;/tr&gt;        &lt;tr&gt;         &lt;td valign="top" width="291"&gt;           &lt;p&gt;ContentPlaceholder&lt;/p&gt;         &lt;/td&gt;          &lt;td valign="top" width="321"&gt;           &lt;p&gt;System.String&lt;/p&gt;         &lt;/td&gt;          &lt;td valign="top" width="285"&gt;           &lt;p&gt;Name of the primary content place holder into which the generated content will be placed. This is the content place holder id the user typed into the Add View dialog&lt;/p&gt;         &lt;/td&gt;       &lt;/tr&gt;        &lt;tr&gt;         &lt;td valign="top" width="291"&gt;           &lt;p&gt;ContentPlaceHolders&lt;/p&gt;         &lt;/td&gt;          &lt;td valign="top" width="322"&gt;           &lt;p&gt;System.Collections.Generic.List&amp;lt;System.String&amp;gt;&lt;/p&gt;         &lt;/td&gt;          &lt;td valign="top" width="285"&gt;           &lt;p&gt;A list of all content place holder ID’s in the master page, if a master page was chosen for this view&lt;/p&gt;         &lt;/td&gt;       &lt;/tr&gt;        &lt;tr&gt;         &lt;td valign="top" width="290"&gt;           &lt;p&gt;LanguageExtension&lt;/p&gt;         &lt;/td&gt;          &lt;td valign="top" width="323"&gt;           &lt;p&gt;System.String&lt;/p&gt;         &lt;/td&gt;          &lt;td valign="top" width="284"&gt;           &lt;p&gt;The output file’s extension (including the period)&lt;/p&gt;         &lt;/td&gt;       &lt;/tr&gt;        &lt;tr&gt;         &lt;td valign="top" width="290"&gt;           &lt;p&gt;ViewDataTypeGenericString&lt;/p&gt;         &lt;/td&gt;          &lt;td valign="top" width="324"&gt;           &lt;p&gt;System.String&lt;/p&gt;         &lt;/td&gt;          &lt;td valign="top" width="284"&gt;           &lt;p&gt;This is a string that is used to output the generics clause for the ‘Inherits’ attribute in the view&amp;#39;s directive (for strongly-typed views).&amp;#160; Example: “&amp;lt;MyType&amp;gt;” or “(Of MyType)”&lt;/p&gt;         &lt;/td&gt;       &lt;/tr&gt;        &lt;tr&gt;         &lt;td valign="top" width="290"&gt;           &lt;p&gt;ViewDataType&lt;/p&gt;         &lt;/td&gt;          &lt;td valign="top" width="325"&gt;           &lt;p&gt;System.Type&lt;/p&gt;         &lt;/td&gt;          &lt;td valign="top" width="284"&gt;           &lt;p&gt;This is a Type object representing the type to which a strongly-typed view is bound. It can be used to get information on the properties in the type and the like&lt;/p&gt;         &lt;/td&gt;       &lt;/tr&gt;     &lt;/tbody&gt;&lt;/table&gt; &lt;/p&gt;  &lt;p&gt;Additionally, there are a few properties exposed by the default ‘Host’ property that you may find useful, such as the path to the template currently being executed.&amp;#160; You can read more about those properties here: &lt;a href="http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.texttemplating.itexttemplatingenginehost_properties.aspx"&gt;http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.texttemplating.itexttemplatingenginehost_properties.aspx&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Summary&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;We hope this article has given you enough information about T4 templates and how to effectively use them in conjunction with the tooling Visual Web Developer provides for ASP.NET MVC.&amp;#160; There is a lot more you can do with T4 than just what we went over in this post, so check out some of the information out there (&lt;a href="http://www.hanselman.com/blog/T4TextTemplateTransformationToolkitCodeGenerationBestKeptVisualStudioSecret.aspx"&gt;Scott Hanselman’s post&lt;/a&gt; is a great place to start) and see what you can come up with.&amp;#160; PLEASE post any comments, suggestions, or questions you have.&amp;#160; Thanks for reading!&lt;/p&gt;  &lt;p&gt;Abhishek Mishra | Software Design Engineer | Visual Studio Web Developer&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://community.icburner.com/aggbug.aspx?PostID=1999" width="1" height="1"&gt;</description><category domain="http://community.icburner.com/blogs/vs2010tests/archive/tags/T4/default.aspx">T4</category><category domain="http://community.icburner.com/blogs/vs2010tests/archive/tags/MVC/default.aspx">MVC</category><category domain="http://community.icburner.com/blogs/vs2010tests/archive/tags/MVC2/default.aspx">MVC2</category></item><item><title>Beginning Mocking With Moq 3</title><link>http://community.icburner.com/blogs/vs2010tests/archive/2009/12/23/beginning-mocking-with-moq-3.aspx</link><pubDate>Wed, 23 Dec 2009 05:36:43 GMT</pubDate><guid isPermaLink="false">7695cfbe-8499-488a-81cc-9a443df3b4ce:1998</guid><dc:creator>革命</dc:creator><slash:comments>0</slash:comments><description>&lt;p&gt;   &lt;p&gt;&lt;a href="http://www.codethinked.com/author/Justin%20Etheredge.aspx"&gt;&lt;/a&gt;&lt;/p&gt; &lt;/p&gt;  &lt;h1&gt;Part 1&lt;/h1&gt;  &lt;p&gt;While I was at the ALT.NET and MVP summits, the one topic that came up over and over again was the fact that we don’t focus on the beginners enough. And not necessarily beginners in the sense of brand new developers, but beginners in terms of those who just haven’t been exposed to many of the concepts that we work with so often. Many of us have forgotten how hard it was to grasp some of these concepts. Since Moq 3 went final while I was out of town, I felt like doing an introduction to mocking using Moq 3 was the perfect place to start!&lt;/p&gt;  &lt;p&gt;At this point many developers are now doing automated testing, but not necessarily unit testing. The reason I say this is that most developers don’t know how to break their applications down so that the pieces can be tested independently. Mocking is an easy way to replace dependencies during testing so that you don’t need to actually call out to a database, web service, file system, or even just another class. The idea is that you are isolating small pieces of functionality during testing, hence why they call it “unit” testing.&lt;/p&gt;  &lt;p&gt;In order to do this you must design your classes to use virtual methods or implement interfaces. To look at a simple example let’s start off with an Order class.&lt;/p&gt;  &lt;p&gt;public class Order&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;public int OrderId { get; set; }&lt;/p&gt;  &lt;p&gt;public decimal OrderTotal { get; set; }&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;Very simple, so that we don’t bury the concept under tons of business logic. The first thing that we are going to do is write the order out to a file, but I want to test this functionality without having to actually write my files somewhere to a disk. To do this I am first going to create an OrderWriter class:&lt;/p&gt;  &lt;p&gt;public class OrderWriter&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;private readonly IFileWriter fileWriter;&lt;/p&gt;  &lt;p&gt;public OrderWriter(IFileWriter fileWriter)&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;this.fileWriter = fileWriter;&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;public void WriteOrder(Order order)&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;fileWriter.WriteLine(String.Format(&amp;quot;{0},{1}&amp;quot;, order.OrderId, order.OrderTotal));&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;As you can see, this class takes an IFileWriter interface in its constructor and then when “WriteOrder” is called, it formats the string and passes it to the fileWriter field. The IFileWriter interface is very simple and looks like this:&lt;/p&gt;  &lt;p&gt;public interface IFileWriter&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;void WriteLine(string line);&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;By using this interface we have isolated the actual writing of the file to the disk from the formatting of the data that is going to be written to the disk. The tests that we wrote to form our above classes (you are using TDD, aren’t you? :-) look like this:&lt;/p&gt;  &lt;p&gt;public class When_an_order_is_to_be_written_to_disk : ContextSpecification&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;private Order order;&lt;/p&gt;  &lt;p&gt;private Mock&amp;lt;IFileWriter&amp;gt; mockFileWriter;&lt;/p&gt;  &lt;p&gt;private OrderWriter orderWriter;&lt;/p&gt;  &lt;p&gt;public override void EstablishContext()&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;order = new Order();&lt;/p&gt;  &lt;p&gt;order.OrderId = 1001;&lt;/p&gt;  &lt;p&gt;order.OrderTotal = 10.53M;&lt;/p&gt;  &lt;p&gt;mockFileWriter = new Mock&amp;lt;IFileWriter&amp;gt;();&lt;/p&gt;  &lt;p&gt;orderWriter = new OrderWriter(mockFileWriter.Object);&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;public override void Because()&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;orderWriter.WriteOrder(order);&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;[Fact]&lt;/p&gt;  &lt;p&gt;public void it_should_pass_data_to_file_writer()&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;mockFileWriter.Verify(fw =&amp;gt; fw.WriteLine(&amp;quot;1001,10.53&amp;quot;), Times.Exactly(1));&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;In this test I am using xUnit, which uses the “Fact” attribute to label something a test. It doesn’t use a “TestFixture” attribute or anything. And it uses the class constructor for setup instead of a method with a “Setup” attribute. Personally I really like many of the design decisions that the xUnit guys took.&lt;/p&gt;  &lt;p&gt;&lt;b&gt;&lt;i&gt;Lame Disclaimer&lt;/i&gt;&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;&lt;i&gt;You may also notice that these tests were written in the Context/Specification manner, which I am taking a risk by using. Not because the style is risky, but because I’ll probably have 800 people ripping apart the way that I did it. Honestly though, if you have any suggestions on how these could be written in a better way, please let me know. For these tests, I tried to stick to vanilla xUnit in order to keep the new concepts as few as possible.&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;While these tests may look very different to you, one of the advantages of this style of test comes in when you run them:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/7851.clip_5F00_image002_5F00_367AD369.gif"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="clip_image002" border="0" alt="clip_image002" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/7444.clip_5F00_image002_5F00_thumb_5F00_3D2DDCEC.gif" width="244" height="38" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;See how you can tell what is going on? When you have multiple tests in each context, it looks even better. The more I talk to people who write tests in this style, the more I am sold on it. But anyways, this post isn’t about unit testing styles, so let’s move on!&lt;/p&gt;  &lt;p&gt;If you go back and look at the test earlier in this post you can see that we are creating a new Order in the setup:&lt;/p&gt;  &lt;p&gt;public override void EstablishContext()&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;order = new Order();&lt;/p&gt;  &lt;p&gt;order.OrderId = 1001;&lt;/p&gt;  &lt;p&gt;order.OrderTotal = 10.53M;&lt;/p&gt;  &lt;p&gt;mockFileWriter = new Mock&amp;lt;IFileWriter&amp;gt;();&lt;/p&gt;  &lt;p&gt;orderWriter = new OrderWriter(mockFileWriter.Object);&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;Here we are setting up the context of the tests. We create a new order, set some values, then declare a mock IFileWriter and then pass it into the OrderWriter class. So we are going to test if we can write the file to disk, but we don’t want to hit the disk. So what is the point? Right? Well, not really, when writing an order to disk in a real application there could be significant logic in how to format the file. The code to actually write the file to disk should be separately tested to make sure it works, but being able to isolate the formatting of the data for the order and test it, is very useful.&lt;/p&gt;  &lt;p&gt;We do this by creating a new “Mock” class and pass it the interface as a generic type parameter that we want to mock. Next we create the “OrderWriter” class and pass in the mocked instance of our IFileWriter interface by accessing the Object property on the Mock&amp;lt;IFileWriter&amp;gt; object. We can’t pass the Mock&amp;lt;IFileWriter&amp;gt; instance to the OrderWriter constructor because it takes an IFileWriter, and this is why the “Object” property is available. Hate to repeat myself, but the process is this:&lt;/p&gt;  &lt;p&gt;1. Create an instance of Moq’s “Mock” class that takes a interface or class with virtual methods as a generic parameter. &lt;/p&gt;  &lt;p&gt;2. Tell the Mock what you want to happen, specifying parameters, and even return values. We will get deeper into this later on. &lt;/p&gt;  &lt;p&gt;3. Get back the mocked interface which will behave in the way in which you told it to. Use this mocked interface in your code. &lt;/p&gt;  &lt;p&gt;4. Call “Verify” or “VerifyAll” on the mock to ensure that what you said would happen actually happened. This step is not always required. &lt;/p&gt;  &lt;p&gt;Once we get the mocked interface we can create the OrderWriter class and pass the mocked interface into it. When we pass the order into it, we will format the order and the mocked interface will get called with the formatted string representing the order. Next we want to actually perform the action that we want to test:&lt;/p&gt;  &lt;p&gt;public override void Because()&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;orderWriter.WriteOrder(order);&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;Here we pass the order into the OrderWriter and then next we assert that the method on the IFileWriter interface was called property with the correct values:&lt;/p&gt;  &lt;p&gt;[Fact]&lt;/p&gt;  &lt;p&gt;public void it_should_pass_data_to_file_writer()&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;mockFileWriter.Verify(fw =&amp;gt; fw.WriteLine(&amp;quot;1001,10.53&amp;quot;), Times.Exactly(1));&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;When we call “Verify” on our mock with a lambda we are telling it to check that the call we pass to it actually occurred. The second parameter that we pass to it (which is optional) tells the mock how many times we expected it to be called. So here we are asking the mockFileWriter object if the “WriteLine” method was called with the value “1001,10.53” exactly one time. If this occurred, then the test will pass.&lt;/p&gt;  &lt;p&gt;In this post we have looked at creating a mock class, tell it that a particular method will be called, and then verify that it actually happened. In the future posts we are going to look at setting up return values, dealing with properties, dealing with parameters that we don’t know at compile time, events, etc… So stay tuned!&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;h1&gt;Part 2 &lt;/h1&gt;  &lt;p&gt;In the previous entry in this series on beginning mocking using Moq, we looked at how to create a mock and then later verify that some method was called. This is probably the most basic usage of a mocking framework, which is to simply verify a method call. One of the things that is a bit confusing when looking at a statement in a test that uses a lambda is to realize that the code you are seeing in the assertion is not actually executing. So when you see a statement like this:&lt;/p&gt;  &lt;pre&gt;mockFileWriter.Verify(fw =&amp;gt; fw.WriteLine(&amp;quot;1001,10.53&amp;quot;), Times.Exactly(1));&lt;/pre&gt;

&lt;p&gt;The lambda inside of the “Verify” method:&lt;/p&gt;

&lt;pre&gt;fw =&amp;gt; fw.WriteLine(&amp;quot;1001,10.53&amp;quot;)&lt;/pre&gt;

&lt;p&gt;Is being turned into an expression tree and then analyzed by Moq, not actually being executed. Whether or not you understand what I mean by that, what you need to understand is that we are merely telling Moq what to look for, not running any code.&lt;/p&gt;

&lt;p&gt;In order to show this a bit more clearly, what would happen if in the above code we wanted to verify that any string was passed into the “WriteLine” method, not just a particular string. Well, we simply have to call the “Verify” method like this:&lt;/p&gt;

&lt;pre&gt;mockFileWriter.Verify(fw =&amp;gt; fw.WriteLine(It.IsAny&amp;lt;string&amp;gt;()), Times.Exactly(1));&lt;/pre&gt;

&lt;p&gt;Here you can see that we replaced the “1001,10.53” string with a method call on the static class “It”:&lt;/p&gt;

&lt;pre&gt;It.IsAny&amp;lt;string&amp;gt;())&lt;/pre&gt;

&lt;p&gt;Now it may be more obvious that this code is not being executed because it no longer looks like a simple method call. You can now see that Moq will look at this method call within the “WriteLine” method and adjust the way that it verifies this method. It will still look for exactly one call to “WriteLine” but it will accept any string passed to it, and not just the one that we had previously specified.&lt;/p&gt;

&lt;p&gt;There are also a few other ways to verify these methods calls, such as IsRegex:&lt;/p&gt;

&lt;pre&gt;fw.WriteLine(It.IsRegex(&amp;quot;^1001&amp;quot;))&lt;/pre&gt;

&lt;p&gt;Here we are matching a regex to check that the string starts with 1001. There is also one additional method called “IsInRange” which will check to see if a numerical value is within a particular range.&lt;/p&gt;

&lt;h5&gt;Verifying With Predicates&lt;/h5&gt;

&lt;p&gt;To take this a step further, we can use any predicate expression to define what we want to verify as well. For those who don’t know, a Predicate is simply a delegate that returns a boolean value. So, a variable goes in, you do some sort of check and then return a true or false. So if we wanted to check for any string that is longer than 3 characters, then we could call the “It.Is” method like this:&lt;/p&gt;

&lt;pre&gt;mockFileWriter.Verify(fw =&amp;gt; fw.WriteLine(It.Is&amp;lt;string&amp;gt;(s =&amp;gt; s.Length &amp;gt; 3)), Times.Exactly(1));&lt;/pre&gt;

&lt;p&gt;Or if we wanted to check that the string started with “1001,10.53” instead of equaling that, then we could do this:&lt;/p&gt;

&lt;pre&gt;mockFileWriter.Verify(fw =&amp;gt; fw.WriteLine(It.Is&amp;lt;string&amp;gt;(s =&amp;gt; s.StartsWith(&amp;quot;1001,10.53&amp;quot;))), Times.Exactly(1));&lt;/pre&gt;

&lt;p&gt;There is no limit to the comparisons that we can do. We could also compare against a local variable:&lt;/p&gt;

&lt;pre&gt;string expectedValue = &amp;quot;1001,10.53&amp;quot;;&lt;/pre&gt;

&lt;pre&gt;mockFileWriter.Verify(fw =&amp;gt; fw.WriteLine(It.Is&amp;lt;string&amp;gt;(s =&amp;gt; s.StartsWith(expectedValue))), Times.Exactly(1));&lt;/pre&gt;

&lt;p&gt;This way we can keep the expected value out of the verify, making it arguably easier to read.&lt;/p&gt;

&lt;h5&gt;Property Verification&lt;/h5&gt;

&lt;p&gt;Now that you know how to verify that a method was called, what happens if we need to verify that a property was set or read? Well, it actually looks very similar to method call verification above. In order to show this, lets define a “FileName” property on the IFileWriter interface that we will set with a filename by the OrderWriter class. This is likely a poor design in a real application, but it will serve our purpose here.&lt;/p&gt;

&lt;p&gt;So now in our OrderWriter we will do this:&lt;/p&gt;

&lt;pre&gt;public void WriteOrder(Order order)&lt;/pre&gt;

&lt;pre&gt;{&lt;/pre&gt;

&lt;pre&gt;&amp;#160;&amp;#160;&amp;#160; fileWriter.FileName = order.OrderId + &amp;quot;.txt&amp;quot;;&lt;/pre&gt;

&lt;pre&gt;&amp;#160;&amp;#160;&amp;#160; fileWriter.WriteLine(String.Format(&amp;quot;{0},{1}&amp;quot;, order.OrderId, order.OrderTotal));&lt;/pre&gt;

&lt;pre&gt;}&lt;/pre&gt;

&lt;p&gt;Here we set the filename using the order id and then call the “WriteLine” method. So we will need another test:&lt;/p&gt;

&lt;pre&gt;[Fact]&lt;/pre&gt;

&lt;pre&gt;public void it_should_set_the_file_name()&lt;/pre&gt;

&lt;pre&gt;{&lt;/pre&gt;

&lt;pre&gt;&amp;#160;&amp;#160;&amp;#160; mockFileWriter.VerifySet(fw =&amp;gt; fw.FileName);&lt;/pre&gt;

&lt;pre&gt;}&lt;/pre&gt;

&lt;p&gt;This test will now only pass if something is assigned to the “FileName” property. The only problem is that we could set anything to this property, it isn’t necessarily what we want. Thankfully Moq provides a way for us to check that it was set to an exact value:&lt;/p&gt;

&lt;pre&gt;mockFileWriter.VerifySet(fw =&amp;gt; fw.FileName = &amp;quot;1001.txt&amp;quot;);&lt;/pre&gt;

&lt;p&gt;Sweet. Everything works as expected. Just as with the methods, we can match against the static “It” class like this:&lt;/p&gt;

&lt;pre&gt;mockFileWriter.VerifySet(fw =&amp;gt; fw.FileName = It.Is&amp;lt;string&amp;gt;(s =&amp;gt; s.StartsWith(&amp;quot;1001&amp;quot;)));&lt;/pre&gt;

&lt;p&gt;So as you can see, properties are just as easy to work with as methods are.&lt;/p&gt;

&lt;h5&gt;Wrap Up&lt;/h5&gt;

&lt;p&gt;In this post we have taken a look at how the verification lambdas work, and how we can use Moq to verify inexact parameter values. We have also taken a look at how we can check parameters using any predicate value. Then finally we take a look at how we can verify property values as well. In future entries in this series we will take a look at returning values, events, callsbacks, etc… So stay tuned!&lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;h1&gt;Part 3 &lt;/h1&gt;

&lt;p&gt;In the previous part of this series, we looked at how you can verify on an interface exactly what was called using Moq’s “Verify” syntax. In this entry we are going to take a look at setting up mocks with return values.&lt;/p&gt;

&lt;h5&gt;Setting Up Return Values&lt;/h5&gt;

&lt;p&gt;If you have ever done mocking before in the past then you probably know that the “classic” way of using mocks is to setup the mock before you call it. So in the last post when we had this line:&lt;/p&gt;

&lt;pre&gt;mockFileWriter.Verify(fw =&amp;gt; fw.WriteLine(&amp;quot;1001,10.53&amp;quot;), Times.Exactly(1));&lt;/pre&gt;

&lt;p&gt;which verifies, after the fact, what was called. In the “classic” way of doing things we could have written the test like this: (In Moq 2 the method was called “Expect” not “Setup”)&lt;/p&gt;

&lt;pre&gt;[Fact]&lt;/pre&gt;

&lt;pre&gt;public void it_should_pass_data_to_file_writer2()&lt;/pre&gt;

&lt;pre&gt;{&lt;/pre&gt;

&lt;pre&gt;&amp;#160;&amp;#160;&amp;#160; var order = new Order();&lt;/pre&gt;

&lt;pre&gt;&amp;#160;&amp;#160;&amp;#160; order.OrderId = 1001;&lt;/pre&gt;

&lt;pre&gt;&amp;#160;&amp;#160;&amp;#160; order.OrderTotal = 10.53M;&lt;/pre&gt;

&lt;pre&gt;&amp;#160;&lt;/pre&gt;

&lt;pre&gt;&amp;#160;&amp;#160;&amp;#160; var mockFileWriter = new Mock&amp;lt;IFileWriter&amp;gt;();&lt;/pre&gt;

&lt;pre&gt;&amp;#160;&amp;#160;&amp;#160; mockFileWriter.Setup(fw =&amp;gt; fw.WriteLine(&amp;quot;1001,10.53&amp;quot;)).AtMostOnce();&lt;/pre&gt;

&lt;pre&gt;&amp;#160;&lt;/pre&gt;

&lt;pre&gt;&amp;#160;&amp;#160;&amp;#160; var orderWriter = new OrderWriter(mockFileWriter.Object);&amp;#160;&amp;#160;&amp;#160; &lt;/pre&gt;

&lt;pre&gt;&amp;#160;&amp;#160;&amp;#160; orderWriter.WriteOrder(order);&lt;/pre&gt;

&lt;pre&gt;&amp;#160;&lt;/pre&gt;

&lt;pre&gt;&amp;#160;&amp;#160;&amp;#160; mockFileWriter.VerifyAll();&lt;/pre&gt;

&lt;pre&gt;}&lt;/pre&gt;

&lt;p&gt;Here you can see that right after we declare the mock we call “Setup” and pass the expectation to it. We then call “AtMostOnce” to make sure that it is only called a single time. After that we actually perform our test actions. At this point though we haven’t asserted anything, so we have to call “VerifyAll” on the mock that was created. This causes all setup calls to be verified, and an exception will be raised if one of the expectations weren’t met.&lt;/p&gt;

&lt;p&gt;So the “Verify” syntax seems so much better, we don’t need to do two calls, or remember to call “VerifyAll” after the fact. So why is the original Setup syntax still there? Well, besides backward compatibility. Part of the reason is that there is one key thing that you can’t do after the fact, and that is setting up return values on method calls. Let’s start this by creating an OrderReader class which uses an IFileReader interface. The IFileReader interface has a line called “ReadLine” which returns a string.&lt;/p&gt;

&lt;p&gt;Since we want to mock this IFileReader and call this method on it that returns a value, we need some way to setup the return value. Thanksfully, Moq provides us with an extremely easy way to do this:&lt;/p&gt;

&lt;pre&gt;public override void EstablishContext()&lt;/pre&gt;

&lt;pre&gt;{&lt;/pre&gt;

&lt;pre&gt;&amp;#160;&amp;#160;&amp;#160; var mockFileReader = new Mock&amp;lt;IFileReader&amp;gt;();&lt;/pre&gt;

&lt;pre&gt;&amp;#160;&amp;#160;&amp;#160; mockFileReader.Setup(fr =&amp;gt; fr.ReadLine()).Returns(&amp;quot;1002,10.34&amp;quot;);&lt;/pre&gt;

&lt;pre&gt;&amp;#160;&lt;/pre&gt;

&lt;pre&gt;&amp;#160;&amp;#160;&amp;#160; orderReader = new OrderReader(mockFileReader.Object);&lt;/pre&gt;

&lt;pre&gt;}&lt;/pre&gt;

&lt;pre&gt;&amp;#160;&lt;/pre&gt;

&lt;pre&gt;public override void Because()&lt;/pre&gt;

&lt;pre&gt;{&lt;/pre&gt;

&lt;pre&gt;&amp;#160;&amp;#160;&amp;#160; order = orderReader.ReadOrder();&lt;/pre&gt;

&lt;pre&gt;}&lt;/pre&gt;

&lt;p&gt;Moq can see the return type of the method that you are passing in, and then lets you return back an instance of that type. In fact, if a method is returning another interface that you need to mock, then you can return a mock type! This let’s you build up more complex interfaces from mocks.&lt;/p&gt;

&lt;p&gt;Now that we have setup the mock and created our order, we simply call the “ReadOrder” method and we get back an order object. All that is left to assert now is that the line from the IFileReader was parsed and turned back into an order correctly:&lt;/p&gt;

&lt;pre&gt;[Fact]&lt;/pre&gt;

&lt;pre&gt;public void it_should_have_order_id_set()&lt;/pre&gt;

&lt;pre&gt;{&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/pre&gt;

&lt;pre&gt;&amp;#160;&amp;#160;&amp;#160; Assert.Equal(1002, order.OrderId);&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/pre&gt;

&lt;pre&gt;}&lt;/pre&gt;

&lt;pre&gt;&amp;#160;&lt;/pre&gt;

&lt;pre&gt;[Fact]&lt;/pre&gt;

&lt;pre&gt;public void it_should_have_order_total_set()&lt;/pre&gt;

&lt;pre&gt;{&lt;/pre&gt;

&lt;pre&gt;&amp;#160;&amp;#160;&amp;#160; Assert.Equal(10.34M, order.OrderTotal);&lt;/pre&gt;

&lt;pre&gt;}&lt;/pre&gt;

&lt;p&gt;And that was easy. But I mentioned earlier that we are able to setup two mocks and have one mock returned from the other mock. How does that work?&lt;/p&gt;

&lt;h5&gt;Returning Mocks From Other Mocks&lt;/h5&gt;

&lt;p&gt;Well, it works just like you are passing a mock to any other method. So if we have two interfaces like this:&lt;/p&gt;

&lt;pre&gt;internal interface IDoSomething&lt;/pre&gt;

&lt;pre&gt;{&lt;/pre&gt;

&lt;pre&gt;&amp;#160;&amp;#160;&amp;#160; IDoSomethingElse GetSomethingElse();&lt;/pre&gt;

&lt;pre&gt;}&lt;/pre&gt;

&lt;pre&gt;&amp;#160;&lt;/pre&gt;

&lt;pre&gt;internal interface IDoSomethingElse&lt;/pre&gt;

&lt;pre&gt;{&lt;/pre&gt;

&lt;pre&gt;&amp;#160;&amp;#160;&amp;#160; string GetSomeValue();&lt;/pre&gt;

&lt;pre&gt;}&lt;/pre&gt;

&lt;p&gt;Then it is as simple as doing this:&lt;/p&gt;

&lt;pre&gt;var mockSomethingElse = new Mock&amp;lt;IDoSomethingElse&amp;gt;();&lt;/pre&gt;

&lt;pre&gt;mockSomethingElse.Setup(mse =&amp;gt; mse.GetSomeValue()).Returns(&amp;quot;Something&amp;quot;);&lt;/pre&gt;

&lt;pre&gt;&amp;#160;&lt;/pre&gt;

&lt;pre&gt;var mockSomething = new Mock&amp;lt;IDoSomething&amp;gt;();&lt;/pre&gt;

&lt;pre&gt;mockSomething.Setup(ms =&amp;gt; ms.GetSomethingElse()).Returns(mockSomethingElse.Object);&lt;/pre&gt;

&lt;p&gt;And there you have it, we have created the IDoSomethingElse mock and setup expectations on its return value. Then we mock IDoSomething and when we setup its method, we simply pass the mock.Object into the “Returns” method.&lt;/p&gt;

&lt;h5&gt;Summary&lt;/h5&gt;

&lt;p&gt;In this post we have looked at setting up return values on mocks so that we can return canned values from them to satisfy the needs of calling classes. If you are setting up return values on mocks and not really verifying anything that was called on the mock, then technically you are not mocking, but instead stubbing. I guess that is a topic for another day though. I hope you enjoyed this entry, and stay tuned for the next post when we will look at mocking multiple interfaces and callbacks.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://community.icburner.com/aggbug.aspx?PostID=1998" width="1" height="1"&gt;</description><category domain="http://community.icburner.com/blogs/vs2010tests/archive/tags/TDD/default.aspx">TDD</category><category domain="http://community.icburner.com/blogs/vs2010tests/archive/tags/Moq/default.aspx">Moq</category></item><item><title>A 26-part series of Business Apps Example for Silverlight 3 &amp; .NET RIA Services July Update</title><link>http://community.icburner.com/blogs/vs2010tests/archive/2009/12/10/a-26-part-series-of-business-apps-example-for-silverlight-3-amp-net-ria-services-july-update.aspx</link><pubDate>Wed, 09 Dec 2009 17:07:49 GMT</pubDate><guid isPermaLink="false">7695cfbe-8499-488a-81cc-9a443df3b4ce:1997</guid><dc:creator>革命</dc:creator><slash:comments>0</slash:comments><description>&lt;h4&gt;&amp;#160;&lt;/h4&gt;  &lt;p&gt;By Brad Abrams, this demo requires:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;&lt;a href="http://www.microsoft.com/express/download/"&gt;VS2008 SP1&lt;/a&gt; (Which includes &lt;a href="http://www.microsoft.com/express/sql/Default.aspx"&gt;Sql Express 2008&lt;/a&gt;) &lt;/li&gt;    &lt;li&gt;&lt;a href="http://silverlight.net/getstarted/silverlight3/default.aspx"&gt;Silverlight 3 RTM&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://code.msdn.microsoft.com/RiaServices"&gt;.NET RIA Services July ‘09 Preview&lt;/a&gt;&lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;&lt;a href="http://brad_abrams.members.winisp.net/Projects/Silverlight3RTM/MyApp.zip"&gt;download the full demo files&lt;/a&gt; and check out the &lt;a href="http://www.hanselman.com/abrams/"&gt;running application&lt;/a&gt;. &lt;/p&gt;  &lt;p&gt;Also check out the author’s &lt;a href="http://visitmix.com/"&gt;Mix09&lt;/a&gt; talk &lt;a href="http://blogs.msdn.com/brada/archive/2009/03/17/mix09-building-amazing-business-applications-with-silverlight-3.aspx"&gt;“building business applications with Silverlight 3&lt;/a&gt;”.&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;a href="http://blogs.msdn.com/brada/archive/2009/07/10/amazing-business-apps-example-updated-for-silverlight-3-rtm-and-net-ria-services-july-update.aspx"&gt;Part 1: Navigation Basics&lt;/a&gt;&lt;/p&gt;    &lt;p&gt;&lt;a href="http://blogs.msdn.com/brada/archive/2009/07/11/business-apps-example-for-silverlight-3-rtm-and-net-ria-services-july-update-part-1-rich-data-query.aspx"&gt;Part 2: Rich Data Query&lt;/a&gt;&lt;/p&gt;    &lt;p&gt;&lt;a href="http://blogs.msdn.com/brada/archive/2009/07/13/business-apps-example-for-silverlight-3-rtm-and-net-ria-services-july-update-part-3-authentication.aspx"&gt;Part 3: Authentication&lt;/a&gt;&lt;/p&gt;    &lt;p&gt;&lt;a href="http://blogs.msdn.com/brada/archive/2009/07/14/business-apps-example-for-silverlight-3-rtm-and-net-ria-services-july-update-part-4-seo-export-to-excel-and-out-of-browser.aspx"&gt;Part 4: SEO, Export to Excel and Out of Browser&lt;/a&gt;&lt;/p&gt;    &lt;p&gt;&lt;a href="http://blogs.msdn.com/brada/archive/2009/07/15/business-apps-example-for-silverlight-3-rtm-and-net-ria-services-july-update-part-5-astoria-add-reference-and-winforms.aspx"&gt;Part 5: Astoria, Add Service Reference and WinForms&lt;/a&gt;&lt;/p&gt;    &lt;p&gt;&lt;a href="http://blogs.msdn.com/brada/archive/2009/07/16/business-apps-example-for-silverlight-3-rtm-and-net-ria-services-july-update-part-6-data-transfer-objects-dtos.aspx"&gt;Part 6: Data Transfer Objects (DTOs)&lt;/a&gt;&lt;/p&gt;    &lt;p&gt;&lt;a href="http://blogs.msdn.com/brada/archive/2009/07/21/business-apps-example-for-silverlight-3-rtm-and-net-ria-services-july-update-part-7-services-based-data-store.aspx"&gt;Part 7: ADO.NET Data Services Based Data Store&lt;/a&gt;&lt;/p&gt;    &lt;p&gt;&lt;a href="http://blogs.msdn.com/brada/archive/2009/07/17/business-apps-example-for-silverlight-3-rtm-and-net-ria-services-july-update-part-8-wcf-based-data-source.aspx"&gt;Part 8: WCF Based Data Source&lt;/a&gt;&lt;/p&gt;    &lt;p&gt;&lt;a href="http://blogs.msdn.com/brada/archive/2009/07/22/business-apps-example-for-silverlight-3-rtm-and-net-ria-services-july-update-part-6-poco-and-authentication-provider.aspx"&gt;Part 9: POCO and Authentication Provider&lt;/a&gt;&lt;/p&gt;    &lt;p&gt;&lt;a href="http://blogs.msdn.com/brada/archive/2009/07/23/business-apps-example-for-silverlight-3-rtm-and-net-ria-services-july-update-part-9-linqtosql.aspx"&gt;Part 10: LinqToSql&lt;/a&gt;&lt;/p&gt;    &lt;p&gt;&lt;a href="http://blogs.msdn.com/brada/archive/2009/07/24/business-apps-example-for-silverlight-3-rtm-and-net-ria-services-july-update-part-11-the-client-only-world.aspx"&gt;Part 11: The Client-Only World&lt;/a&gt;&lt;/p&gt;    &lt;p&gt;&lt;a href="http://blogs.msdn.com/brada/archive/2009/07/27/business-apps-example-for-silverlight-3-rtm-and-net-ria-services-july-update-part-9-dataset.aspx"&gt;Part 12: DataSet&lt;/a&gt;&lt;/p&gt;    &lt;p&gt;&lt;a href="http://blogs.msdn.com/brada/archive/2009/07/28/business-apps-example-for-silverlight-3-rtm-and-net-ria-services-july-update-part-11-the-new-class-library-project.aspx"&gt;Part 13: The New Class Library Project&lt;/a&gt;&lt;/p&gt;    &lt;p&gt;&lt;a href="http://blogs.msdn.com/brada/archive/2009/07/29/business-apps-example-for-silverlight-3-rtm-and-net-ria-services-july-update-part-xx-visual-basic-vb-and-wpf-support.aspx"&gt;Part 14: Visual Basic (VB) and WPF Support&lt;/a&gt;&lt;/p&gt;    &lt;p&gt;&lt;a href="http://blogs.msdn.com/brada/archive/2009/07/30/business-apps-example-for-silverlight-3-rtm-and-net-ria-services-july-update-part-xx-asp-net-mvc.aspx"&gt;Part 15: ASP.NET MVC&lt;/a&gt;&lt;/p&gt;    &lt;p&gt;&lt;a href="http://blogs.msdn.com/brada/archive/2009/07/31/business-apps-example-for-silverlight-3-rtm-and-net-ria-services-july-update-part-xx-exposing-a-wcf-service.aspx"&gt;Part 16: Exposing a WCF Service&lt;/a&gt;&lt;/p&gt;    &lt;p&gt;&lt;a href="http://blogs.msdn.com/brada/archive/2009/08/03/business-apps-example-for-silverlight-3-rtm-and-net-ria-services-july-update-part-xx-evolving-an-application.aspx"&gt;Part 17: Evolving an Application&lt;/a&gt;&lt;/p&gt;    &lt;p&gt;&lt;a href="http://blogs.msdn.com/brada/archive/2009/08/04/business-apps-example-for-silverlight-3-rtm-and-net-ria-services-july-update-part-xx-custom-linq-provider.aspx"&gt;Part 18: Custom Linq Provider&lt;/a&gt;&lt;/p&gt;    &lt;p&gt;&lt;a href="http://blogs.msdn.com/brada/archive/2009/08/05/business-apps-example-for-silverlight-3-rtm-and-net-ria-services-july-update-asp-net-dynamic-data.aspx"&gt;Part 19: ASP.NET Dynamic Data&lt;/a&gt;&lt;/p&gt;    &lt;p&gt;&lt;a href="http://blogs.msdn.com/brada/archive/2009/08/06/business-apps-example-for-silverlight-3-rtm-and-net-ria-services-july-update-part-nhibernate.aspx"&gt;Part 20: NHibernate&lt;/a&gt;&lt;/p&gt;    &lt;p&gt;&lt;a href="http://blogs.msdn.com/brada/archive/2009/08/10/business-apps-example-for-silverlight-3-rtm-and-net-ria-services-july-update-part-hierarchal-data.aspx"&gt;Part 21: Hierarchical Data&lt;/a&gt;&lt;/p&gt;    &lt;p&gt;&lt;a href="http://blogs.msdn.com/brada/archive/2009/08/11/business-apps-example-for-silverlight-3-rtm-and-net-ria-services-july-update-part-22-separate-solution-files.aspx"&gt;Part 22: Separate Solution Files&lt;/a&gt;&lt;/p&gt;    &lt;p&gt;&lt;a href="http://blogs.msdn.com/brada/archive/2009/08/21/business-apps-example-for-silverlight-3-rtm-and-net-ria-services-july-update-part-23-azure.aspx"&gt;Part 23: Azure&lt;/a&gt;&lt;/p&gt;    &lt;p&gt;&lt;a href="http://blogs.msdn.com/brada/archive/2009/08/24/business-apps-example-for-silverlight-3-rtm-and-net-ria-services-july-update-part-24-stored-procedures.aspx"&gt;Part 24: Stored Procedures&lt;/a&gt;&lt;/p&gt;    &lt;p&gt;&lt;a href="http://blogs.msdn.com/brada/archive/2009/09/07/business-apps-example-for-silverlight-3-rtm-and-net-ria-services-july-update-viewmodel.aspx"&gt;Part 25: ViewModel&lt;/a&gt;&lt;/p&gt;    &lt;p&gt;&lt;a href="http://blogs.msdn.com/brada/archive/2009/10/05/business-apps-example-for-silverlight-3-rtm-and-net-ria-services-july-update-part-26-authentication-and-personalization.aspx"&gt;Part 26: Authentication and Personalization&lt;/a&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://community.icburner.com/aggbug.aspx?PostID=1997" width="1" height="1"&gt;</description><category domain="http://community.icburner.com/blogs/vs2010tests/archive/tags/Silverlight/default.aspx">Silverlight</category></item><item><title>ASP.NET 2.0 Membership, Roles, Forms Authentication, and Security Resources – ScottGu’s Blog</title><link>http://community.icburner.com/blogs/vs2010tests/archive/2009/12/10/asp-net-2-0-membership-roles-forms-authentication-and-security-resources-scottgu-s-blog.aspx</link><pubDate>Wed, 09 Dec 2009 17:06:12 GMT</pubDate><guid isPermaLink="false">7695cfbe-8499-488a-81cc-9a443df3b4ce:1996</guid><dc:creator>革命</dc:creator><slash:comments>0</slash:comments><description>&lt;h4&gt;&amp;#160;&lt;/h4&gt;  &lt;h4&gt;The following is excerpt from ScottGu’s Blog:&lt;/h4&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;b&gt;Getting Started with ASP.NET 2.0 Membership, Roles and Forms Authentication Video&lt;/b&gt;&lt;/p&gt;    &lt;p&gt;Watch this &lt;a href="http://download.microsoft.com/download/3/6/0/3604c3d2-0db9-4726-910d-b3b8f93a86e4/hilo_membership-roles_final.wmv"&gt;great online video&lt;/a&gt;. It walks through how to add Forms Authentication (using the &amp;lt;asp:login&amp;gt; control) with a secure Membership Credential Store + Role Based Security to a site, then implement pages that enable Registration (using the &amp;lt;asp:createuserwizard&amp;gt; control) + Change Password (using the &amp;lt;asp:changepassword&amp;gt; control) + Reset Password (using the &amp;lt;asp:recoverypassword&amp;gt; control), and then authorize page access and hide menu navigation links using the role groupings of the authenticated user. The video shows how to-do all of this from scratch in only 17 minutes. You can watch it &lt;a href="http://download.microsoft.com/download/3/6/0/3604c3d2-0db9-4726-910d-b3b8f93a86e4/hilo_membership-roles_final.wmv"&gt;here&lt;/a&gt;. You can also find other great ASP.NET “how to” videos &lt;a href="http://msdn.microsoft.com/asp.net/learning/learn/newtodevelopment/default.aspx"&gt;here&lt;/a&gt;. &lt;/p&gt;    &lt;p&gt;&lt;b&gt;ASP.NET 2.0 Membership and Role Management Overview Articles&lt;/b&gt;&lt;/p&gt;    &lt;p&gt;Here are a few good tutorial articles that provide a good conceptual overview of how the new membership and role management system works. &lt;/p&gt;    &lt;p&gt;Scott Mitchell’s: &lt;a href="http://aspnet.4guysfromrolla.com/articles/120705-1.aspx"&gt;Examining ASP.NET 2.0’s Membership, Roles and Profile (Part 1)&lt;/a&gt;&lt;/p&gt;    &lt;p&gt;Scott Mitchell’s: &lt;a href="http://aspnet.4guysfromrolla.com/articles/121405-1.aspx"&gt;Examining ASP.NET 2.0’s Membership, Roles and Profile (Part 2)&lt;/a&gt;&lt;/p&gt;    &lt;p&gt;Scott Mitchell’s: &lt;a href="http://aspnet.4guysfromrolla.com/articles/040506-1.aspx"&gt;Examining ASP.NET 2.0’s Membership, Roles and Profile (Part 3)&lt;/a&gt;&lt;/p&gt;    &lt;p&gt;Scott Mitchell’s: &lt;a href="http://aspnet.4guysfromrolla.com/articles/050306-1.aspx"&gt;Examining ASP.NET 2.0’s Membership, Roles and Profile (Part 4)&lt;/a&gt;&lt;/p&gt;    &lt;p&gt;Scott Mitchell’s: &lt;a href="http://aspnet.4guysfromrolla.com/articles/060706-1.aspx"&gt;Examining ASP.NET 2.0’s Membership, Roles and Profile (Part 5)&lt;/a&gt;&lt;/p&gt;    &lt;p&gt;MSDN: &lt;a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnpag2/html/PAGExplained0002.asp"&gt;Explained: Forms Authentication in ASP.NET 2.0&lt;/a&gt;&lt;/p&gt;    &lt;p&gt;MSDN: &lt;a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnpag2/html/PAGExplained0001.asp"&gt;Explained: Windows Authentication in ASP.NET 2.0&lt;/a&gt;&lt;/p&gt;    &lt;p&gt;Scott Allen’s: &lt;a href="http://odetocode.com/Articles/427.aspx"&gt;Membership Providers (Part 1)&lt;/a&gt;&lt;/p&gt;    &lt;p&gt;Scott Allen’s: &lt;a href="http://odetocode.com/Articles/428.aspx"&gt;Role Providers (Part 2)&lt;/a&gt;&lt;/p&gt;    &lt;p&gt;&lt;b&gt;ASP.NET 2.0 Security, Membership and Role Management Book&lt;/b&gt;&lt;/p&gt;    &lt;p&gt;Stefan Schackow is the ASP.NET Team technical expert and feature-owner for a lot of the core sub-systems in ASP.NET, and he owned the security, membership and role management features for ASP.NET 2.0. He has recently published an awesome book on ASP.NET Security, Membership and Roles that you can buy for $26 on Amazon &lt;a href="http://www.amazon.com/gp/product/0764596985/sr=8-38/qid=1140774204/ref=sr_1_38/103-7721422-8377424?%5Fencoding=UTF8"&gt;here&lt;/a&gt;. &lt;/p&gt;    &lt;p&gt;&lt;img src="http://images.amazon.com/images/P/0764596985.01._AA240_SCLZZZZZZZ_.jpg" alt="" /&gt;&lt;/p&gt;    &lt;p&gt;You can read two big recommendations of it from ASP.NET MVPs here: &lt;a href="http://blogs.ipona.com/davids/archive/2006/01/24/3732.aspx"&gt;Dave Sussman&lt;/a&gt; and &lt;a href="http://chrison.net/ProfessionalASPNET20SecurityMembershipAndRoleManagement.aspx"&gt;Christoph Wille&lt;/a&gt; I highly recommend getting a copy. &lt;/p&gt;    &lt;p&gt;&lt;b&gt;Setting up Membership + Roles on a SQL 2000 or SQL 2005 Server&lt;/b&gt;&lt;/p&gt;    &lt;p&gt;By default ASP.NET 2.0 auto-creates and uses a SQL Express database to store Membership, Roles and Profile data. If you want to instead use a SQL 2000 or SQL 2005 database, you can easily learn how to configure it &lt;a href="http://weblogs.asp.net/scottgu/archive/2005/08/25/423703.aspx"&gt;using this blog post of mine&lt;/a&gt;. &lt;/p&gt;    &lt;p&gt;&lt;strong&gt;Don’t forget to always set the “applicationName” attribute when configuring ASP.NET Membership, Roles, Profile and other providers.&lt;/strong&gt;&lt;/p&gt;    &lt;p&gt;One common issue people forget to-do when registering membership and other providers is to configure the “applicationName” attribute on the provider declaration.&amp;#160; This can prevent logins from seeming to work when you copy an application to another machine.&amp;#160; This &lt;a href="http://weblogs.asp.net/scottgu/archive/2006/04/22/443634.aspx"&gt;blog post&lt;/a&gt; covers this scenario more and how to fix it. &lt;/p&gt;    &lt;p&gt;&lt;b&gt;Custom Membership and Roles Providers&lt;/b&gt;&lt;/p&gt;    &lt;p&gt;ASP.NET 2.0 ships with built-in SQL Server, SQL Express and Active Directory Membership and Role Providers.&amp;#160; The source code for these built-in providers can now be downloaded from &lt;a href="http://weblogs.asp.net/scottgu/archive/2006/04/13/442772.aspx"&gt;here&lt;/a&gt;. &lt;/p&gt;    &lt;p&gt;The nice thing about the system is that it is entirely extensible, which means you can create and configure your own custom credential/role stores into the system as well (either using the source code from the built-in providers, or just by extending the provider contract). &lt;/p&gt;    &lt;p&gt;The &lt;a href="http://msdn.microsoft.com/asp.net/downloads/providers/"&gt;ASP.NET Provider Toolkit Site&lt;/a&gt; provides tons of content on how to create and build your own providers (including Membership and Role Providers). It also has a link to a fully functional Membership and Role Provider that works with Access databases.&amp;#160; &lt;a href="http://www.devx.com/asp/Article/29256"&gt;This article&lt;/a&gt; also discusses how to build your own Membership Provider, and can be a useful guide to integrating the membership APIs with your own existing database. &lt;/p&gt;    &lt;p&gt;Here is a list of other free custom Membership and Roles providers (with complete source code) that I know of on the web: &lt;/p&gt;    &lt;ul&gt;     &lt;li&gt;       &lt;p&gt;&lt;a href="http://weblogs.asp.net/scottgu/archive/2006/04/13/442772.aspx"&gt;SQL Database Support for ASP.NET Membership, Roles and Personalization&lt;/a&gt;&lt;/p&gt;     &lt;/li&gt;      &lt;li&gt;       &lt;p&gt;&lt;a href="http://www.codeproject.com/aspnet/MySQLMembershipProvider.asp"&gt;MySQL Support for ASP.NET Membership and Roles&lt;/a&gt;&lt;/p&gt;     &lt;/li&gt;      &lt;li&gt;       &lt;p&gt;&lt;a href="http://www.eggheadcafe.com/articles/20051119.asp"&gt;SQLLite3 Support for ASP.NET Membership and Roles&lt;/a&gt;&lt;/p&gt;     &lt;/li&gt;      &lt;li&gt;       &lt;p&gt;&lt;a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnbda/html/bdasamppet4.asp"&gt;Oracle Support for ASP.NET Membership, Roles and Personalization&lt;/a&gt; (note: this is included in the PetShop sample)&lt;/p&gt;     &lt;/li&gt;   &lt;/ul&gt;    &lt;p&gt;You can download and configure your application to use any of the above providers.&amp;#160; The beauty of the system is that the Membership, Roles APIs + Login Controls don’t change at all.&amp;#160; &lt;/p&gt;    &lt;p&gt;&lt;b&gt;Storing Custom Properties about a User during Registration&lt;/b&gt;&lt;/p&gt;    &lt;p&gt;One very common question I see asked a lot is how to store custom properties about a new user as they register on the system (example: zip code, gender, etc). The good news is that it is easy to-do this with the new ASP.NET Profile System and the built-in &amp;lt;asp:createuserwizard&amp;gt; control. &lt;/p&gt;    &lt;p&gt;I have a sample &lt;a href="http://weblogs.asp.net/scottgu/archive/2005/10/18/427754.aspx"&gt;here&lt;/a&gt; that shows how to build a registration system for a site with Membership, Login, Registration, Password Recovery, Change Password, Custom Properties and Roles support – all in 24 lines of code.&amp;#160; If you want, you can combine this with the new SQLTableProvider for the Profile system for greater control over your profile database schema. You can learn about that in my blog post &lt;a href="http://weblogs.asp.net/scottgu/archive/2006/01/10/435038.aspx"&gt;here&lt;/a&gt;. &lt;/p&gt;    &lt;p&gt;&lt;strong&gt;Remote Server Administration Tool Mangement of Membership/Roles&lt;/strong&gt;&lt;/p&gt;    &lt;p&gt;The built-in Web Administration Tool with Visual Web Developer and VS 2005 makes it easy to manage the users and roles for a local ASP.NET application. One common question I get asked is how to manage these users/roles against a remote server (for example: an application running on a remote hoster.&amp;#160; &lt;a href="http://weblogs.asp.net/scottgu/archive/2006/01/09/434925.aspx"&gt;This blog post&lt;/a&gt; of mine points to two different solutions you can use to enable this.&lt;/p&gt;&lt;/blockquote&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://community.icburner.com/aggbug.aspx?PostID=1996" width="1" height="1"&gt;</description><category domain="http://community.icburner.com/blogs/vs2010tests/archive/tags/MVC/default.aspx">MVC</category></item><item><title>Consuming an ASP.NET web service or page method using jQuery</title><link>http://community.icburner.com/blogs/vs2010tests/archive/2009/12/10/consuming-an-asp-net-web-service-or-page-method-using-jquery.aspx</link><pubDate>Wed, 09 Dec 2009 17:02:07 GMT</pubDate><guid isPermaLink="false">7695cfbe-8499-488a-81cc-9a443df3b4ce:1995</guid><dc:creator>革命</dc:creator><slash:comments>0</slash:comments><description>&lt;h4&gt;&amp;#160;&lt;/h4&gt;  &lt;p&gt;&lt;img border="0" alt="Quantcast" src="http://pixel.quantserve.com/pixel/p-ab3gTb8xb3dLg.gif" width="1" height="1" /&gt;The following is a dummy ASP .NET web service. Please note that this service is adorned with the &lt;code&gt;ScriptService &lt;/code&gt;attribute that makes it available to JavaScript clients.&lt;/p&gt;  &lt;h6&gt;Listing 2: A Dummy web service &lt;/h6&gt;  &lt;ol&gt;   &lt;li&gt;[WebService(Namespace = &amp;quot;http://tempuri.org/&amp;quot;)]&amp;#160;&amp;#160; &lt;/li&gt;    &lt;li&gt;[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]&amp;#160;&amp;#160; &lt;/li&gt;    &lt;li&gt;[System.Web.Script.Services.ScriptService]&amp;#160;&amp;#160; &lt;/li&gt;    &lt;li&gt;public class dummyWebservice : System.Web.Services.WebService&amp;#160;&amp;#160; &lt;/li&gt;    &lt;li&gt;{&amp;#160;&amp;#160; &lt;/li&gt;    &lt;li&gt;&amp;#160; [WebMethod()]&amp;#160;&amp;#160; &lt;/li&gt;    &lt;li&gt;public string HelloToYou(string name)&amp;#160;&amp;#160; &lt;/li&gt;    &lt;li&gt;&amp;#160; {&amp;#160;&amp;#160; &lt;/li&gt;    &lt;li&gt;return &amp;quot;Hello &amp;quot; + name;&amp;#160;&amp;#160; &lt;/li&gt;    &lt;li&gt;&amp;#160; }&amp;#160;&amp;#160; &lt;/li&gt;    &lt;li&gt;&amp;#160; [WebMethod()]&amp;#160;&amp;#160; &lt;/li&gt;    &lt;li&gt;public string sayHello()&amp;#160;&amp;#160; &lt;/li&gt;    &lt;li&gt;&amp;#160; {&amp;#160;&amp;#160; &lt;/li&gt;    &lt;li&gt;return &amp;quot;hello &amp;quot;;&amp;#160;&amp;#160; &lt;/li&gt;    &lt;li&gt;&amp;#160; }&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/li&gt;    &lt;li&gt;}&amp;#160; &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;For example, we can call a specific web method in a web service as such.&lt;/p&gt;  &lt;h6&gt;Listing 4: JQuery .ajax command &lt;/h6&gt;  &lt;ol&gt;   &lt;li&gt;&amp;#160; $.ajax({&amp;#160;&amp;#160; &lt;/li&gt;    &lt;li&gt;&amp;#160; type: &amp;quot;POST&amp;quot;,&amp;#160;&amp;#160; &lt;/li&gt;    &lt;li&gt;&amp;#160; contentType: &amp;quot;application/json; charset=utf-8&amp;quot;,&amp;#160;&amp;#160; &lt;/li&gt;    &lt;li&gt;&amp;#160; url: &amp;quot;WebService.asmx/WebMethodName&amp;quot;,&amp;#160;&amp;#160; &lt;/li&gt;    &lt;li&gt;&amp;#160; data: &amp;quot;{}&amp;quot;,&amp;#160;&amp;#160; &lt;/li&gt;    &lt;li&gt;&amp;#160; dataType: &amp;quot;json&amp;quot; &lt;/li&gt;    &lt;li&gt;});&amp;#160; &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;Two things are worth noting in the above JQuery AJAX call. First, we must specify the contentType’s value as &lt;code&gt;application/json; charset=utf-8&lt;/code&gt;, and the &lt;code&gt;dataType &lt;/code&gt;as &lt;code&gt;json&lt;/code&gt;; second, to make a &lt;code&gt;GET &lt;/code&gt;request, we leave the &lt;code&gt;data &lt;/code&gt;value as empty. &lt;/p&gt;  &lt;p&gt;So put it together, the following code demonstrates how we would use JQuery to call the web service we created above. &lt;/p&gt;  &lt;h6&gt;Listing 5: Calling a web service using jQuery &lt;/h6&gt;  &lt;ol&gt;   &lt;li&gt;&amp;lt;%@ Page Language=&amp;quot;C#&amp;quot; %&amp;gt; &lt;/li&gt;    &lt;li&gt;&amp;lt;%@ Import Namespace=&amp;quot;System.Web.Services&amp;quot; %&amp;gt; &lt;/li&gt;    &lt;li&gt;&amp;lt;!DOCTYPE html PUBLIC &amp;quot;-//W3C//DTD XHTML 1.0 Transitional//EN&amp;quot;&amp;#160;&amp;#160;&amp;#160; &lt;/li&gt;    &lt;li&gt;&amp;quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&amp;quot;&amp;gt; &lt;/li&gt;    &lt;li&gt;&amp;lt;html &amp;gt; &lt;/li&gt;    &lt;li&gt;&amp;lt;head id=&amp;quot;Head1&amp;quot; runat=&amp;quot;server&amp;quot;&amp;gt; &lt;/li&gt;    &lt;li&gt;&amp;lt;title&amp;gt;ASP.NET AJAX Web Services: Web Service Sample Page&amp;lt;/title&amp;gt; &lt;/li&gt;    &lt;li&gt;&amp;lt;script type=&amp;quot;text/javascript&amp;quot; src=&amp;quot;http://ajax.googleapis.com/ajax/libs/jQuery/1.2.6/jQuery.min.js&amp;quot;&amp;gt; &lt;/li&gt;    &lt;li&gt;&amp;lt;/script&amp;gt; &lt;/li&gt;    &lt;li&gt;&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt; &lt;/li&gt;    &lt;li&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; $(document).ready(function() {&amp;#160;&amp;#160; &lt;/li&gt;    &lt;li&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; $(&amp;quot;#sayHelloButton&amp;quot;).click(function(event){&amp;#160;&amp;#160; &lt;/li&gt;    &lt;li&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; $.ajax({&amp;#160;&amp;#160; &lt;/li&gt;    &lt;li&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; type: &amp;quot;POST&amp;quot;,&amp;#160;&amp;#160; &lt;/li&gt;    &lt;li&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; url: &amp;quot;dummyWebsevice.asmx/HelloToYou&amp;quot;,&amp;#160;&amp;#160; &lt;/li&gt;    &lt;li&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; data: &amp;quot;{‘name’: ‘&amp;quot; + $(‘#name’).val() + &amp;quot;’}&amp;quot;,&amp;#160;&amp;#160; &lt;/li&gt;    &lt;li&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; contentType: &amp;quot;application/json; charset=utf-8&amp;quot;,&amp;#160;&amp;#160; &lt;/li&gt;    &lt;li&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; dataType: &amp;quot;json&amp;quot;,&amp;#160;&amp;#160; &lt;/li&gt;    &lt;li&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; success: function(msg) {&amp;#160;&amp;#160; &lt;/li&gt;    &lt;li&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; AjaxSucceeded(msg);&amp;#160;&amp;#160; &lt;/li&gt;    &lt;li&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; },&amp;#160;&amp;#160; &lt;/li&gt;    &lt;li&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; error: AjaxFailed&amp;#160;&amp;#160; &lt;/li&gt;    &lt;li&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; });&amp;#160;&amp;#160; &lt;/li&gt;    &lt;li&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; });&amp;#160;&amp;#160; &lt;/li&gt;    &lt;li&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; });&amp;#160;&amp;#160; &lt;/li&gt;    &lt;li&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; function AjaxSucceeded(result) {&amp;#160;&amp;#160; &lt;/li&gt;    &lt;li&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; alert(result.d);&amp;#160;&amp;#160; &lt;/li&gt;    &lt;li&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }&amp;#160;&amp;#160; &lt;/li&gt;    &lt;li&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; function AjaxFailed(result) {&amp;#160;&amp;#160; &lt;/li&gt;    &lt;li&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; alert(result.status + ‘ ‘ + result.statusText);&amp;#160;&amp;#160; &lt;/li&gt;    &lt;li&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/li&gt;    &lt;li&gt;&amp;lt;/script&amp;gt; &lt;/li&gt;    &lt;li&gt;&amp;lt;/head&amp;gt; &lt;/li&gt;    &lt;li&gt;&amp;lt;body&amp;gt; &lt;/li&gt;    &lt;li&gt;&amp;lt;form id=&amp;quot;form1&amp;quot; runat=&amp;quot;server&amp;quot;&amp;gt; &lt;/li&gt;    &lt;li&gt;&amp;lt;h1&amp;gt; Calling ASP.NET AJAX Web Services with jQuery &amp;lt;/h1&amp;gt; &lt;/li&gt;    &lt;li&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Enter your name:&amp;#160;&amp;#160;&amp;#160; &lt;/li&gt;    &lt;li&gt;&amp;lt;input id=&amp;quot;name&amp;quot; /&amp;gt; &lt;/li&gt;    &lt;li&gt;&amp;lt;br /&amp;gt; &lt;/li&gt;    &lt;li&gt;&amp;lt;input id=&amp;quot;sayHelloButton&amp;quot; value=&amp;quot;Say Hello&amp;quot; &lt;/li&gt;    &lt;li&gt;type=&amp;quot;button&amp;quot; /&amp;gt; &lt;/li&gt;    &lt;li&gt;&amp;lt;/form&amp;gt; &lt;/li&gt;    &lt;li&gt;&amp;lt;/body&amp;gt; &lt;/li&gt;    &lt;li&gt;&amp;lt;/html&amp;gt; &lt;/li&gt; &lt;/ol&gt;  &lt;h5&gt;Calling an ASP .NET page method &lt;/h5&gt;  &lt;p&gt;Listing 6: A dummy hello world page method &lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;[WebMethod()]&amp;#160;&amp;#160; &lt;/li&gt;    &lt;li&gt;public static string sayHello()&amp;#160;&amp;#160; &lt;/li&gt;    &lt;li&gt;{&amp;#160;&amp;#160; &lt;/li&gt;    &lt;li&gt;return &amp;quot;hello &amp;quot;;&amp;#160;&amp;#160; &lt;/li&gt;    &lt;li&gt;}&amp;#160;&amp;#160;&amp;#160; &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;Please note that page methods must be declared as static, meaning a page method is completely self-contained, and no page controls are accessible through the page method. For example, if you have a textbox on the web form, there is no way the page method can get or set its value. Consequently any changes with regards to the controls have no affect on the page method. It is stateless and it does not carry any of the view-state data typically carries around by an asp .NET page.&lt;/p&gt;  &lt;p&gt;We use the same jQuery command &lt;code&gt;$.ajax &lt;/code&gt;to call a page method, as shown in the following example.&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;&amp;#160;&amp;#160; &lt;/li&gt;    &lt;li&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; $(document).ready(function() {&amp;#160;&amp;#160; &lt;/li&gt;    &lt;li&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; $.ajax({&amp;#160;&amp;#160; &lt;/li&gt;    &lt;li&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; type: &amp;quot;POST&amp;quot;,&amp;#160;&amp;#160; &lt;/li&gt;    &lt;li&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; url: &amp;quot;pagemethod.aspx/sayHello&amp;quot;,&amp;#160;&amp;#160; &lt;/li&gt;    &lt;li&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; contentType: &amp;quot;application/json; charset=utf-8&amp;quot;,&amp;#160;&amp;#160; &lt;/li&gt;    &lt;li&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; data: &amp;quot;{}&amp;quot;,&amp;#160;&amp;#160; &lt;/li&gt;    &lt;li&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; dataType: &amp;quot;json&amp;quot;,&amp;#160;&amp;#160; &lt;/li&gt;    &lt;li&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; success: AjaxSucceeded,&amp;#160;&amp;#160; &lt;/li&gt;    &lt;li&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; error: AjaxFailed&amp;#160;&amp;#160; &lt;/li&gt;    &lt;li&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; });&amp;#160;&amp;#160;&amp;#160; &lt;/li&gt;    &lt;li&gt;&amp;#160;&amp;#160;&amp;#160; });&amp;#160;&amp;#160; &lt;/li&gt;    &lt;li&gt;function AjaxSucceeded(result) {&amp;#160;&amp;#160; &lt;/li&gt;    &lt;li&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; alert(result.d);&amp;#160;&amp;#160; &lt;/li&gt;    &lt;li&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }&amp;#160;&amp;#160; &lt;/li&gt;    &lt;li&gt;function AjaxFailed(result) {&amp;#160;&amp;#160; &lt;/li&gt;    &lt;li&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; alert(result.status + ‘ ‘ + result.statusText);&amp;#160;&amp;#160; &lt;/li&gt;    &lt;li&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/li&gt;    &lt;li&gt;&amp;#160; &amp;lt;/script&amp;gt;&amp;#160;&amp;#160;&amp;#160; &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;For more info please visit Xun Ding’s excellent article &lt;a href="http://dotnetslackers.com/articles/ajax/Using-jQuery-with-ASP-NET.aspx#consuming-a-web-service-using-jquery"&gt;Using jQuery with ASP .NET&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;h4&gt;The Best jQuery Modal Dialog Plugins&lt;/h4&gt;  &lt;p&gt;&lt;img border="0" alt="Quantcast" src="http://pixel.quantserve.com/pixel/p-ab3gTb8xb3dLg.gif" width="1" height="1" /&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://vincenthomedev.files.wordpress.com/2009/05/image.png"&gt;&lt;img title="image" border="0" alt="image" src="http://vincenthomedev.files.wordpress.com/2009/05/image-thumb.png?w=162&amp;amp;h=183" width="162" height="183" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Via &lt;a href="http://www.blogrammierer.de/jquery-die-22-besten-modal-fenster-plugins/"&gt;http://www.blogrammierer.de/jquery-die-22-besten-modal-fenster-plugins/&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://community.icburner.com/aggbug.aspx?PostID=1995" width="1" height="1"&gt;</description><category domain="http://community.icburner.com/blogs/vs2010tests/archive/tags/jQuery/default.aspx">jQuery</category></item><item><title>Introduction to the simplest Mock Framework for .NET – Moq</title><link>http://community.icburner.com/blogs/vs2010tests/archive/2009/12/10/introduction-to-the-simplest-mock-framework-for-net-moq.aspx</link><pubDate>Wed, 09 Dec 2009 16:57:31 GMT</pubDate><guid isPermaLink="false">7695cfbe-8499-488a-81cc-9a443df3b4ce:1994</guid><dc:creator>革命</dc:creator><slash:comments>0</slash:comments><description>&lt;h4&gt;&amp;#160;&lt;/h4&gt;  &lt;p&gt;Rate This&lt;/p&gt;  &lt;p&gt;&lt;img border="0" alt="Quantcast" src="http://pixel.quantserve.com/pixel/p-ab3gTb8xb3dLg.gif" width="1" height="1" /&gt;&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;     &lt;h5&gt;&lt;a href="http://code.google.com/p/moq/"&gt;Moq Home&lt;/a&gt;&lt;/h5&gt;   &lt;/li&gt; &lt;/ul&gt;  &lt;ul&gt;   &lt;li&gt;     &lt;h5&gt;Screencasts – &lt;a href="http://www.dimecasts.net/Casts/CastDetails/8"&gt;Introduction to Mocking with Moq&lt;/a&gt;&lt;/h5&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;h5&gt;&lt;a href="http://blog.decayingcode.com/2009/02/part-2-basic-of-mocking-with-moq.html"&gt;Basic Mocking with Moq&lt;/a&gt;&lt;/h5&gt;   &lt;/li&gt; &lt;/ul&gt;  &lt;h5&gt;Methods&lt;/h5&gt;  &lt;pre&gt;&lt;a href="http://vincenthomedev.files.wordpress.com/2009/02/image4.png"&gt;&lt;img title="image" border="0" alt="image" src="http://vincenthomedev.files.wordpress.com/2009/02/image-thumb4.png?w=601&amp;amp;h=427" width="601" height="427" /&gt;&lt;/a&gt; &lt;/pre&gt;

&lt;h5&gt;Matching Arguments&lt;/h5&gt;

&lt;p&gt;&lt;a href="http://vincenthomedev.files.wordpress.com/2009/02/image5.png"&gt;&lt;img title="image" border="0" alt="image" src="http://vincenthomedev.files.wordpress.com/2009/02/image-thumb5.png?w=640&amp;amp;h=136" width="640" height="136" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h5&gt;Properties&lt;/h5&gt;

&lt;pre&gt;&lt;a href="http://vincenthomedev.files.wordpress.com/2009/02/image6.png"&gt;&lt;img title="image" border="0" alt="image" src="http://vincenthomedev.files.wordpress.com/2009/02/image-thumb6.png?w=429&amp;amp;h=74" width="429" height="74" /&gt;&lt;/a&gt; &lt;/pre&gt;

&lt;h5&gt;Callbacks&lt;/h5&gt;

&lt;p&gt;&lt;a href="http://vincenthomedev.files.wordpress.com/2009/02/image7.png"&gt;&lt;img title="image" border="0" alt="image" src="http://vincenthomedev.files.wordpress.com/2009/02/image-thumb7.png?w=409&amp;amp;h=213" width="409" height="213" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h5&gt;Verification&lt;/h5&gt;

&lt;pre&gt;&lt;a href="http://vincenthomedev.files.wordpress.com/2009/02/image8.png"&gt;&lt;img title="image" border="0" alt="image" src="http://vincenthomedev.files.wordpress.com/2009/02/image-thumb8.png?w=287&amp;amp;h=51" width="287" height="51" /&gt;&lt;/a&gt; &lt;/pre&gt;

&lt;h5&gt;Also…&lt;/h5&gt;

&lt;pre&gt;API (lots of examples) - &lt;a href="http://www.clariusconsulting.net/labs/moq/index.html"&gt;API documentation&lt;/a&gt;&lt;/pre&gt;

&lt;pre&gt;Stephen Walter - &lt;a href="http://stephenwalther.com/blog/archive/2008/06/12/tdd-introduction-to-moq.aspx"&gt;TDD : Introduction to Moq&lt;/a&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://community.icburner.com/aggbug.aspx?PostID=1994" width="1" height="1"&gt;</description><category domain="http://community.icburner.com/blogs/vs2010tests/archive/tags/VS2010/default.aspx">VS2010</category><category domain="http://community.icburner.com/blogs/vs2010tests/archive/tags/Moq/default.aspx">Moq</category></item><item><title>NUnit running VS10 code</title><link>http://community.icburner.com/blogs/vs2010tests/archive/2009/12/09/nunit-running-vs10-code.aspx</link><pubDate>Wed, 09 Dec 2009 14:26:13 GMT</pubDate><guid isPermaLink="false">7695cfbe-8499-488a-81cc-9a443df3b4ce:1993</guid><dc:creator>革命</dc:creator><slash:comments>0</slash:comments><description>&lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;I&amp;#39;ve downloaded the NUnit 2.5 source and opened the VS2008 solution in the VS2010 beta. Once the conversion finished I opened all the projects and changed the target framework setting for all the projects to &amp;quot;.NET Framework 4.0&amp;quot;. I then built the solution without any errors. I can now use the NUnit GUI app to run tests built for .NET 4.0. I&amp;#39;ve not done exhaustive testing of this build so there may be problems, but for my purposes it works fine. &lt;p&gt;Update: It is not necessary to rebuild NUnit. I discovered that if you add the following to the relevant NUnit config file you can run a test dll built for .NET 4.0. &lt;p&gt;Under &amp;lt;configuration&amp;gt; add:&lt;pre&gt;&lt;code&gt;&amp;lt;startup&amp;gt;&lt;br /&gt;&amp;nbsp; &amp;lt;requiredRuntime version=&amp;quot;v4.0.20506&amp;quot; /&amp;gt;&lt;br /&gt;&amp;lt;/startup&amp;gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;and under &amp;lt;runtime&amp;gt; add:&lt;pre&gt;&lt;code&gt;&amp;lt;loadFromRemoteSources enabled=&amp;quot;true&amp;quot; /&amp;gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Just adding the requireRuntime element is insufficient and results in an security related error message mentioning the loadFromRemoteSources switch. I found something about the switch on &lt;a href="http://social.msdn.microsoft.com/Forums/en-US/webdevelopmentprerelease/thread/ea9b9cab-cbfd-496d-8a81-7b3dd06e8c23"&gt;this&lt;/a&gt; social.msdn post, where &lt;a href="http://blogs.rev-net.com/ddewinter/"&gt;David DeWinter&lt;/a&gt; wrote: 
&lt;blockquote&gt;
&lt;p&gt;Caveat: I&amp;#39;m not on the security team but will attempt to answer this nonetheless... 
&lt;p&gt;What&amp;#39;s happening here is that the build tasks for Silverlight are attempting to load an assembly that, in previous versions of the CLR, would classify it as a partial trust assembly based on its evidence (e.g. its zone) according to CAS policy. 
&lt;p&gt;In CLR 4.0, CAS policy is totally deprecated and is not even enabled by default. Under the circumstances, though, it appears the CLR throws an Exception when what would be a partial trust load in CLR 2.0 is a full trust load in CLR 4.0. 
&lt;p&gt;The loadFromRemoteSources switch the Exception message refers to is in the runtime element under configuration and looks like this: 
&lt;p&gt;&amp;lt;runtime&amp;gt; &lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;lt;loadFromRemoteSources enabled=&amp;quot;true|false&amp;quot; /&amp;gt;&lt;br /&gt;&amp;lt;/runtime&amp;gt;
&lt;p&gt;This will not enable legacy CAS policy but will allow you (or, in this case, the build system) to load remote assemblies with the same permissions as the host AppDomain. In this case it seems as though you could modify the configuration for the build system (which I assume in this case would be Visual Studio: %ProgramFiles%\Microsoft Visual Studio 10.0\Common7\IDE\devenv.exe.config) to enable this switch. 
&lt;p&gt;If you don&amp;#39;t want to modify that configuratino then you can set the environment variable COMPLUS_EnableLegacyCASPolicy to 1, which will enable CAS Policy that was present in CLR 2.0 and also allow Silverlight to load this task. 
&lt;p&gt;Hope that helps. David &lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;&lt;code&gt;&lt;/code&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;A lot of improvements have been made in the unit testing space w/ VS 2010 including a full test management system in TFS.&amp;nbsp; In fact, this is one of the hottest areas for 2010.&lt;br /&gt;Here are some helpful links:
&lt;p&gt;&lt;a href="http://blogs.msdn.com/amit_chatterjee/archive/2009/10/23/what-s-new-in-test-and-lab-management-in-vs-2010-beta-2.aspx"&gt;http://blogs.msdn.com/amit_chatterjee/archive/2009/10/23/what-s-new-in-test-and-lab-management-in-vs-2010-beta-2.aspx&lt;/a&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/vstsqualitytools/default.aspx"&gt;http://blogs.msdn.com/vstsqualitytools/default.aspx&lt;/a&gt;
&lt;p&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/bb385901(VS.100).aspx"&gt;http://msdn.microsoft.com/en-us/library/bb385901(VS.100).aspx&lt;/a&gt;
&lt;p&gt;Why were you considering the move to NUnit?&lt;/p&gt;&lt;code&gt;&lt;pre&gt;&amp;nbsp;&lt;/pre&gt;
&lt;p&gt;Thanks for the links; they do provide some useful information. The improvements in test management are obviously welcome. However, I was hoping for new features in the unit testing libraries and the execution infrastructure itself.
&lt;p&gt;I am interested in a comparison of the NUnit support for parametrized unit tests and the Visual Studio (VS) 2010 unit testing (MSTest) support for the same.
&lt;p&gt;&lt;a href="http://nunit.org/index.php?p=parameterizedTests&amp;amp;r=2.5.2"&gt;http://nunit.org/index.php?p=parameterizedTests&amp;amp;r=2.5.2&lt;/a&gt;
&lt;p&gt;Currently I think MSTest has limited support for parametrized tests and it is very cumbersome and constraining. I would like to be able to specify data values inline and not have to go to heavy weight solutions like enabling deployment and using an excel sheet or a relational database. We have used Pex for some scenarios where we needed parametrized support but Pex to me is not a replacement for native support of parametrized tests in the unit testing framework.
&lt;p&gt;&lt;a href="http://research.microsoft.com/en-us/projects/Pex/"&gt;http://research.microsoft.com/en-us/projects/Pex/&lt;/a&gt;
&lt;p&gt;Another issue with MSTest, and this could just be ignorance on my part, is the lack of extensibility in MSTest to facilitate new scenarios. The unit testing technology area is a fast moving one (e.g. the developers of NUnit realized that they had to provide features on par with other frameworks like MbUnit and xUnit to remain competitive) with MSTest one is stuck with the current release of VS and one has to wait till the next full release of VS to get any new features for unit testing whereas with NUnit and the like you can get new features and bugs fixes quickly.
&lt;p&gt;Another issue for me is limitations on how third party tools like TeamCity can work with MSTest e.g. TeamCity cannot show the results of unit tests on-the-fly it can only show them when all the tests have run, it can do that for NUnit and my guess is that this is because MSTest makes it very difficult if not impossible for third party tools to get the results on-the-fly.
&lt;p&gt;&lt;a href="http://www.jetbrains.com/teamcity/"&gt;http://www.jetbrains.com/teamcity/&lt;/a&gt;
&lt;p&gt;&lt;a href="http://www.jetbrains.net/confluence/display/TCD4/MSTest+Support"&gt;http://www.jetbrains.net/confluence/display/TCD4/MSTest+Support&lt;/a&gt;&lt;pre&gt;&amp;nbsp;&lt;/pre&gt;
&lt;p&gt;MS appears to have finally caved on categories in VS 2010 
&lt;p&gt;http://msdn.microsoft.com/en-us/library/dd286595(VS.100).aspx &lt;a href="http://msdn.microsoft.com/en-us/library/ms182489(VS.100).aspx#category"&gt;http://msdn.microsoft.com/en-us/library/ms182489(VS.100).aspx#category&lt;/a&gt; &lt;pre&gt;&amp;nbsp;&lt;/pre&gt;
&lt;h6&gt;&lt;a href="http://blogs.blackmarble.co.uk/blogs/bm-bloggers/archive/2006/06/14/5255.aspx"&gt;MSTest and CruiseControl .NET &lt;/a&gt;&lt;/h6&gt;
&lt;p&gt;I have been trying to get Visual Studio 2005 Team Developer style unit tests working within CruiseControl. 
&lt;p&gt;The &lt;a href="http://confluence.public.thoughtworks.org/display/CCNET/Using+CruiseControl.NET+with+MSTest"&gt;documention&lt;/a&gt; says it should work, but is a little scant as to the detail of how to do it. So now I have it all going I thought an example of the working &lt;em&gt;ccnet.config&lt;/em&gt; file with some comments might help other people trying to get this going.
&lt;p&gt;So the background is I have a VS.NET 2005 solution (&lt;strong&gt;&lt;em&gt;My Sample.sln&lt;/em&gt;&lt;/strong&gt;) with some projects in it. One of these is a Test Project (&lt;strong&gt;&lt;em&gt;TestProject.csproj). &lt;/em&gt;&lt;/strong&gt;This contains some test which can be run via the Test menu option is VS.NET.
&lt;p&gt;&lt;u&gt;CCNET.CONFIG&lt;/u&gt;
&lt;p&gt;&amp;lt;project name=&amp;quot;My Sample&amp;quot;&amp;gt;&lt;br /&gt;&amp;lt;!--Here you put any other project level settings--&amp;gt;&lt;br /&gt;&amp;lt;!--the working directory is used for all relative file references--&amp;gt;&lt;br /&gt;&amp;lt;workingDirectory&amp;gt;C:\projects\My Sample&amp;lt;/workingDirectory&amp;gt;
&lt;p&gt;&amp;lt;!--Normally you would have all your source control bits here--&amp;gt;
&lt;p&gt;&amp;lt;tasks&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;!--We use the Visual Studio build model, you could also use the MSBUILD--&amp;gt;&lt;br /&gt;&amp;lt;devenv&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;solutionfile&amp;gt;&amp;quot;C:\projects\My Sample\My Sample.sln&amp;quot;&amp;lt;/solutionfile&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;configuration&amp;gt;Debug&amp;lt;/configuration&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;buildtype&amp;gt;Build&amp;lt;/buildtype&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;!--Comment out the project block so it build the whole solution--&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;!--&amp;lt;project&amp;gt;MyProject&amp;lt;/project&amp;gt;--&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;executable&amp;gt;&amp;quot;C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\devenv.com&amp;quot;&amp;lt;/executable&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;buildTimeoutSeconds&amp;gt;90&amp;lt;/buildTimeoutSeconds&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/devenv&amp;gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;exec&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;!--Call a batch file that contains &lt;strong&gt;&lt;em&gt;del testResults.trx&lt;/em&gt;&lt;/strong&gt; --&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;!--this is required as MsTest will not create the file if it exists--&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;!--this could be merged with the mstext action in a single batch file--&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;executable&amp;gt;deleteTestLog.bat&amp;lt;/executable&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;baseDirectory&amp;gt;C:\projects\My Sample&amp;lt;/baseDirectory&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;buildArgs&amp;gt;&amp;lt;/buildArgs&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;buildTimeoutSeconds&amp;gt;30&amp;lt;/buildTimeoutSeconds&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/exec&amp;gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;exec&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;!--Call mstest to run the tests contained in the TestProject --&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;executable&amp;gt;C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\mstest.exe&amp;lt;/executable&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;baseDirectory&amp;gt;C:\projects\My Sample&amp;lt;/baseDirectory&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;!--testcontainer: points to the DLL that contains the tests --&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;!--runconfig: points to solutions testrunconfig that is created by vs.net, list what test to run --&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;!--resultsfile: normally the test run log is written to the uniquely named testresults directory&amp;nbsp; --&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;!--&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; this option causes a fixed name copy of the file to be written as well --&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;buildArgs&amp;gt;/testcontainer:testproject\bin\debug\testproject.dll /runconfig:localtestrun.Testrunconfig /resultsfile:testResults.trx&amp;lt;/buildArgs&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;buildTimeoutSeconds&amp;gt;30&amp;lt;/buildTimeoutSeconds&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/exec&amp;gt;
&lt;p&gt;&amp;lt;/tasks&amp;gt;
&lt;p&gt;&amp;lt;publishers&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;!--to get the test results in the dashboard we have to merge the results XML file --&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;!--the project working directory is used as the base path here --&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;merge&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;files&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;file&amp;gt;testResults.trx&amp;lt;/file&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/files&amp;gt;&lt;br /&gt;&amp;lt;/merge&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;!--this is the line I missed for ages, without it you get strange &lt;em&gt;missing publisher log errors&lt;/em&gt; --&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;xmllogger /&amp;gt;&lt;br /&gt;&amp;lt;/publishers&amp;gt;
&lt;p&gt;&amp;lt;/project&amp;gt;&lt;br /&gt;&amp;lt;/cruisecontrol&amp;gt;
&lt;p&gt;&lt;u&gt;DASHBOARD.CONFIG&lt;/u&gt;
&lt;p&gt;By default with CCNET build 1277 has the entry to display MSTest results in the summary. If you want the results on a separate menu item (like nUnit or FxCop) then the dashboard.config should contain the following bits
&lt;p&gt;&amp;lt;buildPlugins&amp;gt;&lt;br /&gt;&amp;lt;buildReportBuildPlugin&amp;gt;&lt;br /&gt;&amp;lt;xslFileNames&amp;gt;&lt;br /&gt;&amp;lt;!--all these xsl entries are in the 1277 build --&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;lt;xslFile&amp;gt;xsl\header.xsl&amp;lt;/xslFile&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;lt;xslFile&amp;gt;xsl\modifications.xsl&amp;lt;/xslFile&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;lt;xslFile&amp;gt;xsl\compile.xsl&amp;lt;/xslFile&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;lt;xslFile&amp;gt;xsl\unittests.xsl&amp;lt;/xslFile&amp;gt;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;lt;xslFile&amp;gt;xsl\MsTestSummary.xsl&amp;lt;/xslFile&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;lt;xslFile&amp;gt;xsl\fxcop-summary.xsl&amp;lt;/xslFile&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;lt;xslFile&amp;gt;xsl\NCoverSummary.xsl&amp;lt;/xslFile&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;lt;xslFile&amp;gt;xsl\SimianSummary.xsl&amp;lt;/xslFile&amp;gt;&lt;br /&gt;&amp;lt;/xslFileNames&amp;gt;&lt;br /&gt;&amp;lt;/buildReportBuildPlugin&amp;gt;
&lt;p&gt;&amp;lt;buildLogBuildPlugin /&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;lt;xslReportBuildPlugin description=&amp;quot;NUnit Details&amp;quot; actionName=&amp;quot;NUnitDetailsBuildReport&amp;quot; xslFileName=&amp;quot;xsl\tests.xsl&amp;quot; /&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;lt;xslReportBuildPlugin description=&amp;quot;NUnit Timings&amp;quot; actionName=&amp;quot;NUnitTimingsBuildReport&amp;quot; xslFileName=&amp;quot;xsl\timing.xsl&amp;quot; /&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;lt;xslReportBuildPlugin description=&amp;quot;NAnt Output&amp;quot; actionName=&amp;quot;NAntOutputBuildReport&amp;quot; xslFileName=&amp;quot;xsl\Nant.xsl&amp;quot; /&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;lt;xslReportBuildPlugin description=&amp;quot;NAnt Timings&amp;quot; actionName=&amp;quot;NAntTimingsBuildReport&amp;quot; xslFileName=&amp;quot;xsl\NantTiming.xsl&amp;quot; /&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;lt;xslReportBuildPlugin description=&amp;quot;FxCop Report&amp;quot; actionName=&amp;quot;FxCopBuildReport&amp;quot; xslFileName=&amp;quot;xsl\FxCopReport.xsl&amp;quot; /&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;lt;xslReportBuildPlugin description=&amp;quot;NCover Report&amp;quot; actionName=&amp;quot;NCoverBuildReport&amp;quot; xslFileName=&amp;quot;xsl\NCover.xsl&amp;quot; /&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;lt;xslReportBuildPlugin description=&amp;quot;Simian Report&amp;quot; actionName=&amp;quot;SimianBuildReport&amp;quot; xslFileName=&amp;quot;xsl\SimianReport.xsl&amp;quot;/&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;lt;!--add the following line to add the extra menu item--&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;lt;xslReportBuildPlugin description=&amp;quot;MSTest Report&amp;quot; actionName=&amp;quot;MSTESTReport&amp;quot; xslFileName=&amp;quot;xsl\MsTestSummary.xsl&amp;quot;/&amp;gt;&lt;br /&gt;&amp;lt;/buildPlugins&amp;gt;
&lt;p&gt;&amp;nbsp; &lt;h5&gt;&lt;a href="http://blog.typemock.com/2009/03/how-to-check-exception-message-using-ms.html"&gt;How to check Exception message using MS Test&lt;/a&gt;&lt;/h5&gt;
&lt;p&gt;In Typemock we use both NUnit and MSTest to run our unit tests. This practice enables us to check that Isolator works fine on both unit testing framework. Most of NUnit attributes can be translated fully into MSTest attributes (and vise-versa) there is one attribute we tend to use that works differently in MSTest - &lt;a href="http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.testtools.unittesting.expectedexceptionattribute.aspx"&gt;ExpectedException&lt;/a&gt;.
&lt;p&gt;ExpectedException attribute is used to specify that a test should throw an exception to pass, both framework let the user define the type of the exception thrown (i.e. typeof(ApplicationException)) the big difference between the framework lies in the 2nd (optional)&amp;nbsp; parameter of that attribute - the Message.
&lt;p&gt;While NUnit compares the massage to the exception&amp;#39;s message MSTest does not. At first I though it was a bug but further investigation revealed that this was done intentionally, Microsoft decision was that the message should be only descriptive and used to associate a message to the exception and not check it.
&lt;p&gt;So what could a TDD developer do if he wants to write a test that checks the exception message as well?
&lt;p&gt;One solution is to add code to the test to check the exception&amp;#39;s message:
&lt;p&gt;[TestMethod]
&lt;p&gt;[ExpectedException(typeof(ApplicationException))]
&lt;p&gt;public void AddNewUser_UserEmailIsEmpty_ThrowException()
&lt;p&gt;{
&lt;p&gt;try
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;p&gt;// This line should throw an exception
&lt;p&gt;UserConnector.AddNewUser(&amp;quot;user1&amp;quot;, &amp;quot;&amp;quot;);
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;p&gt;catch (ApplicationException exc)
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;p&gt;Assert.AreEqual(&amp;quot;Error: user&amp;#39;s email address missing&amp;quot;, exc.Message);
&lt;p&gt;throw;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;p&gt;}
&lt;p&gt;You can read more about this method at &lt;a href="http://imistaken.blogspot.com/2008/09/mstest-expectedexception-and-exception.html"&gt;IMistaken Blog&lt;/a&gt;.
&lt;p&gt;The problem with this solution is that whenever I need to check an exception message I need to write ~4 more lines of code that makes my test less readable and somewhat error prone.
&lt;p&gt;After digging a bit on the net I found a better solution, it seems that both &lt;a href="http://www.codeplex.com/xunit/Wiki/View.aspx?title=Comparisons&amp;amp;referringTitle=Home#attributes"&gt;XUnit&lt;/a&gt; and &lt;a href="http://www.mbunit.com/"&gt;MBUnit&lt;/a&gt; uses Assert.Throws method instead of an attribute to check for expected exceptions.
&lt;p&gt;First I&amp;#39;ve created a new class &lt;em&gt;MyAssert&lt;/em&gt; that handles the exception verification logic:
&lt;p&gt;public class MyAssert
&lt;p&gt;{
&lt;p&gt;public static void Throws&amp;lt;T&amp;gt;(Action action, string expectedMessage) where T : Exception
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;p&gt;try
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;p&gt;action.Invoke();
&lt;p&gt;Assert.Fail(&amp;quot;Exception of type {0} should be thrown.&amp;quot;, typeof(T));
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;p&gt;catch (T exc)
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;p&gt;Assert.AreEqual(expectedMessage, exc.Message);
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;p&gt;}
&lt;p&gt;Then all I needed to do is use the new class whenever I needed to test for an exception and verify its message:
&lt;p&gt;[TestMethod]
&lt;p&gt;public void AddNewUser_UserEmailIsEmpty_ThrowException()
&lt;p&gt;{
&lt;p&gt;MyAssert.Throws&amp;lt;ApplicationException&amp;gt;(
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; () =&amp;gt; UserConnector.AddNewUser(&amp;quot;user1&amp;quot;, &amp;quot;&amp;quot;),
&lt;p&gt;&amp;quot;Error: user&amp;#39;s email address missing&amp;quot;);
&lt;p&gt;}
&lt;p&gt;Although this solution seems more complicated at first it does have two advantages:
&lt;ol&gt;
&lt;li&gt;I don&amp;#39;t need to write the verification logic anymore 
&lt;li&gt;I can specify the exact line in which I expect the exception to be thrown from. &lt;/li&gt;&lt;/ol&gt;
&lt;p&gt;Some would claim that using &lt;em&gt;Throws &lt;/em&gt;is an over specification of the test but I don&amp;#39;t think so. If using Assert calls during unit tests to check that specific line of test returned specific value is fine so does testing that a specific line throw a specific exception is acceptable as well.
&lt;p&gt;After using &lt;em&gt;MyAssert.Throws&lt;/em&gt; for a while I have to say I prefer it to using &lt;em&gt;ExpectedException&lt;/em&gt; attribute because of the specific meaning it bring to my unit tests.&lt;pre&gt;&amp;nbsp;&lt;/pre&gt;
&lt;h4&gt;MSBuild, NAnt, NUnit, MSTest, and frustration &lt;/h4&gt;
&lt;p&gt;Oh bother. Visual Studio 2003 and Cruise Control.NET. Simple and elegant. A basic NAnt script to build the solution and you&amp;#39;re good to go. Run NUnit, output goes to a format CC can understand and Bob&amp;#39;s yer uncle. Let me quantify this. Our cruise server has a subversion client (command line) and the .NET 1.1 SDK. Visual Studio isn&amp;#39;t installed because, duh, it&amp;#39;s a server and cruise just needs something to build the system with.
&lt;p&gt;Enter Visual Studio 2005. I just recently setup CI for our 2005 projects but it&amp;#39;s just plain ugly, in so many ways. First there was trying to get the system to build using MSBuild. That was fine because you can simply enter this:
&lt;p&gt;&lt;em&gt;msbuild /t:rebuild solutionname.sln&lt;/em&gt;
&lt;p&gt;(or whatever target you want like Debug or Release)
&lt;p&gt;Like I said, if that&amp;#39;s all it was no problem but it gets real ugly real fast.
&lt;p&gt;First there&amp;#39;s VSTS unit test projects. The team is all equipped with Visual Studio Team Suite. An expensive proposition, but one made long ago by someone wiser than me. No problem though. We&amp;#39;re not really using the Test Manager much, there are no automated web tests, so we just write unit tests (and run them with &lt;a href="http://weblogs.asp.net/nunitaddin/default.aspx"&gt;Jamie Cansdales&lt;/a&gt; excellent &lt;a href="http://www.testdriven.net/"&gt;TestDriven.NET&lt;/a&gt;). However when MSBuild gets ahold of a solution that contains a VS unit test project it needs some additional set of assemblies (assemblies buried in the GAC_MSIL and other places). The snippet in the ccnet.config file to get MSBuild going was pretty straight forward:
&lt;p&gt;&lt;em&gt;&amp;lt;msbuild&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;executable&amp;gt;C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\MSBuild.exe&amp;lt;/executable&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;workingDirectory&amp;gt;D:\ccnet\projects\ProjectName&amp;lt;/workingDirectory&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;projectFile&amp;gt;SolutionName.sln&amp;lt;/projectFile&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;buildArgs&amp;gt;/noconsolelogger /p:Configuration=AutomatedBuild /v:diag&amp;lt;/buildArgs&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;targets&amp;gt;Build&amp;lt;/targets&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;timeout&amp;gt;600&amp;lt;/timeout&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;logger&amp;gt;C:\Program Files\CruiseControl.NET\server\ThoughtWorks.CruiseControl.MsBuild.dll&amp;lt;/logger&amp;gt;&lt;br /&gt;&amp;lt;/msbuild&amp;gt;&lt;/em&gt;
&lt;p&gt;Through brute force (run MSBuild, figure out what assembly it needs, go find it, lather, rinse, repeat) I was able to get a 2005 solution (with unit test projects) to compile. However actually running the tests is another story. Again brute force reigned supreme here as I trodded through an hour or two of running MSTest.exe to try to coax a couple hundred unit tests to run. The cc.config entry for getting some unit tests looks something like this:
&lt;p&gt;&lt;em&gt;&amp;lt;exec&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;executable&amp;gt;C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\MSTest.exe&amp;lt;/executable&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;baseDirectory&amp;gt;d:\ccnet\projects\ProjectName&amp;lt;/baseDirectory&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;buildArgs&amp;gt;/testcontainer:Source\Tests\UnitTests\bin\AutomatedBuild\UnitTests.dll /runconfig:localtestrun.Testrunconfig /resultsfile:testResults.trx&amp;lt;/buildArgs&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;buildTimeoutSeconds&amp;gt;600&amp;lt;/buildTimeoutSeconds&amp;gt;&lt;br /&gt;&amp;lt;/exec&amp;gt;&lt;/em&gt;
&lt;p&gt;Remember that I said this sever did not have Visual Studio installed. For the VS2005 solutions, I just installed the .NET SDK 2.0 and that was good enough. Although MSTest.exe isn&amp;#39;t included, I snagged the file (and it&amp;#39;s crazy set of additional DLLs scattered all over the hard drive) from another system and stuck it where the EXE was so it would be happy.&amp;nbsp; &lt;p&gt;No dice on running MSTest against a unit test project. It started down the path of running the test, but then hit a crazy COM error (CLSID not registered) and that was enough for me. No way I&amp;#39;m going to track down all the stupid COM registry settings for Visual Studio 2005. And what the hell was this? COM? I thought we got rid of that about 3 compilers ago?
&lt;p&gt;So I was stuck to installing a full Team Suite on the server. Okay, I&amp;#39;ll bite. I mean, I don&amp;#39;t need everything so it&amp;#39;ll be okay (I keep telling myself as I watch a million registry entries fill up). A few hours later and I&amp;#39;m staring at my command prompt again and type in my MSTest.exe command. And a dialog box pops up. Yup, a modal dialog box that tells me something is wrong (I don&amp;#39;t remember the specifics but it wasn&amp;#39;t very informative).
&lt;p&gt;Visual Studio was installed fine and I could compile and run and build the solution I was trying to, but testing from the command line with MSTest.exe was a no-go. No matter how hard I tried, how much I cleaned up, or how many virgins I sacrificed it just won&amp;#39;t go. And there&amp;#39;s another problem. With 2003 and our NUnit tests, we go some nice stats. Timings, informative messages, all that good stuff. With MSTest we get nothing (other than x number of tests ran and maybe a failure, but I couldn&amp;#39;t get that far to see if it would give the details of the failure). On top of that, the MSBuild logger bites and produces about 10,000 lines of gobbly-gook that isn&amp;#39;t very useful. Yes, I could spend my time writing new xslt to make it pretty, trim out the &amp;quot;Everything was okay&amp;quot; lines that fill up the MSBuild task logger but I think that&amp;#39;s not value-added at my rates.
&lt;p&gt;Here&amp;#39;s a sample email I got from the build which gives you an idea of how useless a CC.NET/MSBuild/MSTest combo is:
&lt;p&gt;BUILD SUCCESSFUL
&lt;p&gt;Project: &lt;br /&gt;PROJECTNAME
&lt;p&gt;Date of build: &lt;br /&gt;12/8/2006 8:08:30 AM
&lt;p&gt;Running time: &lt;br /&gt;00:00:55
&lt;p&gt;Integration Request: &lt;br /&gt;intervalTrigger triggered a build (ForceBuild)
&lt;p&gt;Errors (1) 
&lt;p&gt;D:\ccnet\projects\PROJECTNAME\Source\Reports\ServerReports\ServerReports.rptproj (2,1): error MSB4041: The default XML namespace of the project must be the MSBuild XML namespace. If the project is authored in the MSBuild 2003 format, please add xmlns=&amp;quot;http://schemas.microsoft.com/developer/msbuild/2003&amp;quot; to the &amp;amp;lt;Project&amp;amp;gt; element. If the project has been authored in the old 1.0 or 1.2 format, please convert it to MSBuild 2003 format.
&lt;p&gt;Warnings (1) 
&lt;p&gt;Source\Reports\ServerReports\ServerReports.rptproj (,): warning MSB4122: Scanning project dependencies for project &amp;quot;Source\Reports\ServerReports\ServerReports.rptproj&amp;quot; failed. The default XML namespace of the project must be the MSBuild XML namespace. If the project is authored in the MSBuild 2003 format, please add xmlns=&amp;quot;http://schemas.microsoft.com/developer/msbuild/2003&amp;quot; to the &amp;amp;lt;Project&amp;amp;gt; element. If the project has been authored in the old 1.0 or 1.2 format, please convert it to MSBuild 2003 format. D:\ccnet\projects\BRMS\Source\Reports\ServerReports\ServerReports.rptproj
&lt;p&gt;Tests run: 0, Failures: 0, Not run: 0, Time: 0 seconds 
&lt;p&gt;No Tests Run
&lt;p&gt;This project doesn&amp;#39;t have any tests
&lt;p&gt;Modifications since last build (0) 
&lt;p&gt;It&amp;#39;s ugly. Really ugly. MSBuild produces a ton of crazy output. Writing a new MSBuild file is no walk in the park and even for someone like me that knows NAnt quite well, I&amp;#39;m still wrapping my head around how MSBuild does stuff. I had to create a special configuration inside of Visual Studio to omit our Report project because MSBuild can&amp;#39;t build them (hence the target AutomatedBuild above which is not the same configuration that our developers use and something I don&amp;#39;t like doing because that&amp;#39;s one point of a CI server, consistent builds for everyone). 
&lt;p&gt;From the output above, Cruise said the build was okay but there&amp;#39;s an error message that came out of the MSBuild logger (our report project). This is a 2005 project so the information makes no sense (I belive it&amp;#39;s a bug that&amp;#39;s logged but who knows when it might get fixed). And I really can&amp;#39;t integrate the MSTest output into the email because, well, there is none. There&amp;#39;s a hundred tests or so in this project but the logger doesn&amp;#39;t produce anything.&amp;nbsp; &lt;p&gt;Additionaly, there are some project types MSBuild can&amp;#39;t handle and again, it takes a rocket scientist to create an MSBuild file (even using something cool like &lt;a href="http://www.attrice.info/msbuild/"&gt;MSBuild Sidekick&lt;/a&gt;) that can call another MSBuild task and exclude certain projects. This certainly isn&amp;#39;t as easy as it was in 2003 where you just created an exclusion list (we excluded our client app as there was no extra license for the grid control and a modal dialog came up when the trial version was even looked at by the compiler).
&lt;p&gt;Okay, this is mostly a rant but there&amp;#39;s some wisdom here. Continuous Integration does &lt;strong&gt;not&lt;/strong&gt; need to be this hard. CruiseControl.NET is an excellent tool and very flexible with new tools and integrating output from those tools. However when those tools require a million registry settings and even more DLLs (put in very specific places, trust me, you can&amp;#39;t just toss them in the GAC and call it a day) and dump gobs of XML that no mere mortal (well maybe DonXml could) would be able to translate, it&amp;#39;s just wrong. And as for the built-in Team Build that you could us, that&amp;#39;s equally as useless as a) you can&amp;#39;t schedule builds to trigger off of code checkins and b) again it requires a full Team Suite client to be installed on the server. Worst case scenario when I first started setting up CC.NET servers it took 4 hours. Now I can get it done in an hour (which includes testing the build of the first project). I&amp;#39;ve already spent a good day on just trying to get something to compile. It&amp;#39;s compiling now but the output is crap and no running of tests and thats just not good enough for me. You &lt;em&gt;can&lt;/em&gt; get MSBuild and (maybe) MSTest running with CruiseControl.NET. It&amp;#39;s not impossible. If you install the full client and your projects are &amp;quot;just right&amp;quot; it&amp;#39;ll work but the output isn&amp;#39;t that hot and you&amp;#39;ll watch your server CPU slam when compiles happen.
&lt;p&gt;My advice, avoid trying to combine MSBuild, MSTest, and CruiseControl and stick to NAnt, and NUnit (using MSBuild if you have to when building 2005 solutions).
&lt;p&gt;Needless to say I&amp;#39;m looking at one option right now. Dumping the install of VS2005 on the server, changing all our unit tests back to NUnit and using NAnt to do everything (and just calling MSBuild as an exec task for VS2005 projects). I still need to run 2003 projects so our CI server is going to look like a Frankenstein monster by the time I&amp;#39;m done, building VS2003 and VS2005 projects, running NUnit, MSBuild, NAnt, Simian, FxCop and whatever else we have in our mix. Even given that, using NAnt the output will be simpler (and integrate well with CC.NET), test output will be useful and informative, and I don&amp;#39;t need to install a $15,000 piece of software on a server that has the distinct possibility to pop-up a modal dialog someday when it can&amp;#39;t find some registry key.
&lt;p&gt;Grrr. Argh.&lt;pre&gt;&lt;br /&gt;&amp;nbsp;&lt;/pre&gt;&lt;/code&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://community.icburner.com/aggbug.aspx?PostID=1993" width="1" height="1"&gt;</description><category domain="http://community.icburner.com/blogs/vs2010tests/archive/tags/VS2010/default.aspx">VS2010</category><category domain="http://community.icburner.com/blogs/vs2010tests/archive/tags/NUnit/default.aspx">NUnit</category></item><item><title>Walkthrough: Embedding Localized Resources for a JavaScript File</title><link>http://community.icburner.com/blogs/vs2010tests/archive/2009/11/06/walkthrough-embedding-localized-resources-for-a-javascript-file.aspx</link><pubDate>Fri, 06 Nov 2009 03:07:56 GMT</pubDate><guid isPermaLink="false">7695cfbe-8499-488a-81cc-9a443df3b4ce:1992</guid><dc:creator>革命</dc:creator><slash:comments>0</slash:comments><description>&lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;This walkthrough describes how to include an ECMAScript (JavaScript) file as an embedded resource in an assembly, and how to include localized strings for use in the JavaScript file. You embed a JavaScript file in an assembly when you have a client script component that must be distributed with the assembly. The JavaSc&lt;a name="ddd"&gt;&lt;/a&gt;ript file can be referenced from a Web application that registers the assembly. You embed localized resources when you have to modify values that are used by the JavaScript file for different languages and cultures.&lt;/p&gt;  &lt;p&gt;&lt;b&gt;&lt;a href="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/7455.clip_5F00_image001_5F00_0BCF6563.gif"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="clip_image001" border="0" alt="clip_image001" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/5775.clip_5F00_image001_5F00_thumb_5F00_60D6B5B6.gif" width="1" height="1" /&gt;&lt;/a&gt;&lt;/b&gt;&lt;b&gt; Prerequisites &lt;/b&gt;&lt;/p&gt;  &lt;p&gt;To implement the procedures in this walkthrough you need:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Visual Studio or Visual Web Developer 2010 Express.&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&lt;a href="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/2677.clip_5F00_image0011_5F00_755C0534.gif"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="clip_image001[1]" border="0" alt="clip_image001[1]" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/7532.clip_5F00_image0011_5F00_thumb_5F00_42F831B5.gif" width="1" height="1" /&gt;&lt;/a&gt; Creating an Assembly that Contains an Embedded JavaScript File &lt;/p&gt;  &lt;p&gt;You will begin by creating an assembly (.dll file) that contains the JavaScript file that you want to treat as a resource. You will do so by creating &lt;b&gt;a class library project&lt;/b&gt; in Visual Studio, which creates an assembly as its output.&lt;/p&gt;  &lt;p&gt;&lt;b&gt;To embed a client script file and resources in an assembly&lt;/b&gt;&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;In Visual Studio, create a new &lt;b&gt;class library project&lt;/b&gt; named LocalizingScriptResources.&lt;/li&gt;    &lt;li&gt;Add references to the System.Web and System.Web.Extensions assemblies to the project.&lt;/li&gt;    &lt;li&gt;Add a new JScript file to the project named CheckAnswer.js.&lt;/li&gt;    &lt;li&gt;Add the following code to the CheckAnswer.js file. &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;function CheckAnswer()&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;var firstInt = $get(&amp;#39;firstNumber&amp;#39;).innerText;&lt;/p&gt;  &lt;p&gt;var secondInt = $get(&amp;#39;secondNumber&amp;#39;).innerText;&lt;/p&gt;  &lt;p&gt;var userAnswer = $get(&amp;#39;userAnswer&amp;#39;);&lt;/p&gt;  &lt;p&gt;if ((Number.parseLocale(firstInt) + Number.parseLocale(secondInt)) == userAnswer.value)&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;alert(Answer.Correct);&lt;/p&gt;  &lt;p&gt;return true;&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;else&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;alert(Answer.Incorrect);&lt;/p&gt;  &lt;p&gt;return false;&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;The script checks the user&amp;#39;s result for adding two numbers. It uses the &lt;b&gt;alert&lt;/b&gt; function to let the user know whether the answer is correct. The message displayed in the &lt;b&gt;alert&lt;/b&gt; dialog box is read from a localized resource without a postback to the server. &lt;/p&gt;  &lt;p&gt;A placeholder named &lt;b&gt;Answer&lt;/b&gt; is used in the script to identify which resource files contain the localized strings. The Answer placeholder will be defined later in this procedure.&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;In the &lt;b&gt;Properties&lt;/b&gt; window for &lt;b&gt;CheckAnswer.js&lt;/b&gt;, set &lt;b&gt;Build Action&lt;/b&gt; to &lt;b&gt;Embedded Resource&lt;/b&gt;.&lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;&lt;a href="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/8037.clip_5F00_image002_5F00_71EDE5D3.gif"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="clip_image002" border="0" alt="clip_image002" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/8424.clip_5F00_image002_5F00_thumb_5F00_0A8013D5.gif" width="430" height="107" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Add a class to the project named ClientVerification.&lt;/li&gt;    &lt;li&gt;Replace any code in the ClientVerification class file with the following code:&lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;using System;&lt;/p&gt;  &lt;p&gt;using System.Collections.Generic;&lt;/p&gt;  &lt;p&gt;using System.Text;&lt;/p&gt;  &lt;p&gt;using System.Web.UI;&lt;/p&gt;  &lt;p&gt;using System.Web.UI.HtmlControls;&lt;/p&gt;  &lt;p&gt;using System.Web.UI.WebControls;&lt;/p&gt;  &lt;p&gt;using System.Resources;&lt;/p&gt;  &lt;p&gt;namespace LocalizingScriptResources&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;public class ClientVerification : Control&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;private Button _button;&lt;/p&gt;  &lt;p&gt;private Label _firstLabel;&lt;/p&gt;  &lt;p&gt;private Label _secondLabel;&lt;/p&gt;  &lt;p&gt;private TextBox _answer;&lt;/p&gt;  &lt;p&gt;private int _firstInt;&lt;/p&gt;  &lt;p&gt;private int _secondInt;&lt;/p&gt;  &lt;p&gt;protected override void CreateChildControls()&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;Random random = new Random();&lt;/p&gt;  &lt;p&gt;_firstInt = random.Next(0, 20);&lt;/p&gt;  &lt;p&gt;_secondInt = random.Next(0, 20);&lt;/p&gt;  &lt;p&gt;ResourceManager rm = new ResourceManager(&amp;quot;LocalizingScriptResources.VerificationResources&amp;quot;, this.GetType().Assembly);&lt;/p&gt;  &lt;p&gt;Controls.Clear();&lt;/p&gt;  &lt;p&gt;_firstLabel = new Label();&lt;/p&gt;  &lt;p&gt;_firstLabel.ID = &amp;quot;firstNumber&amp;quot;;&lt;/p&gt;  &lt;p&gt;_firstLabel.Text = _firstInt.ToString();&lt;/p&gt;  &lt;p&gt;_secondLabel = new Label();&lt;/p&gt;  &lt;p&gt;_secondLabel.ID = &amp;quot;secondNumber&amp;quot;;&lt;/p&gt;  &lt;p&gt;_secondLabel.Text = _secondInt.ToString();&lt;/p&gt;  &lt;p&gt;_answer = new TextBox();&lt;/p&gt;  &lt;p&gt;_answer.ID = &amp;quot;userAnswer&amp;quot;;&lt;/p&gt;  &lt;p&gt;_button = new Button();&lt;/p&gt;  &lt;p&gt;_button.ID = &amp;quot;Button&amp;quot;;&lt;/p&gt;  &lt;p&gt;_button.Text = rm.GetString(&amp;quot;Verify&amp;quot;);&lt;/p&gt;  &lt;p&gt;_button.OnClientClick = &amp;quot;return CheckAnswer();&amp;quot;;&lt;/p&gt;  &lt;p&gt;Controls.Add(_firstLabel);&lt;/p&gt;  &lt;p&gt;Controls.Add(new LiteralControl(&amp;quot; + &amp;quot;));&lt;/p&gt;  &lt;p&gt;Controls.Add(_secondLabel);&lt;/p&gt;  &lt;p&gt;Controls.Add(new LiteralControl(&amp;quot; = &amp;quot;));&lt;/p&gt;  &lt;p&gt;Controls.Add(_answer);&lt;/p&gt;  &lt;p&gt;Controls.Add(_button);&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;The code creates a custom ASP.NET control. It contains two &lt;a href="http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.label(VS.100).aspx"&gt;Label&lt;/a&gt; controls, a &lt;a href="http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.textbox(VS.100).aspx"&gt;TextBox&lt;/a&gt; control, and a &lt;a href="http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.button(VS.100).aspx"&gt;Button&lt;/a&gt; control. The code displays two randomly generated integers and provides a text box for an answer. When the button is clicked, the CheckAnswer function is called.&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Add a resources file to the project and name it VerificationResources.resx.&lt;/li&gt;    &lt;li&gt;Add a string resource named &lt;b&gt;Correct&lt;/b&gt; with a value of &amp;quot;Yes, your answer is correct.&amp;quot;&lt;/li&gt;    &lt;li&gt;Add a string resource named &lt;b&gt;Incorrect&lt;/b&gt; with a value of &amp;quot;No, your answer is incorrect.&amp;quot;&lt;/li&gt;    &lt;li&gt;Add a string resource named &lt;b&gt;Verify&lt;/b&gt; with a value of &amp;quot;Verify Answer&amp;quot;. &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;This resource is not retrieved by using client script. Instead, it is used to set to the &lt;a href="http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.button.text(VS.100).aspx"&gt;Text&lt;/a&gt; property of the &lt;a href="http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.button(VS.100).aspx"&gt;Button&lt;/a&gt; control when the button is created.&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Save and close the &lt;b&gt;VerificationResources.resx&lt;/b&gt; file.&lt;/li&gt;    &lt;li&gt;Add a resources file named &lt;b&gt;VerificationResources.it.resx &lt;/b&gt;to the project.&lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;This file will contain resource strings in Italian.&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Add a string resource named &lt;b&gt;Correct&lt;/b&gt; with a value of &amp;quot;Si, la risposta e’ corretta.&amp;quot;&lt;/li&gt;    &lt;li&gt;Add a string resource named &lt;b&gt;Incorrect&lt;/b&gt; with a value of &amp;quot;No, la risposta e’ sbagliata.&amp;quot;&lt;/li&gt;    &lt;li&gt;Add a string resource named &lt;b&gt;Verify&lt;/b&gt; with a value of &amp;quot;Verificare la risposta&amp;quot;. &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;As with the &amp;quot;Verify&amp;quot; resource that you created in English, this resource is not retrieved by using client script. Instead, it is used to set the &lt;a href="http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.button.text(VS.100).aspx"&gt;Text&lt;/a&gt; property of the &lt;a href="http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.button(VS.100).aspx"&gt;Button&lt;/a&gt; control when the button is created.&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Save and close the &lt;b&gt;VerificationResources.it.resx&lt;/b&gt; file.&lt;/li&gt;    &lt;li&gt;Add the following line to the &lt;b&gt;AssemblyInfo&lt;/b&gt; file. You can specify any name for the type name in the &lt;a href="http://msdn.microsoft.com/en-us/library/system.web.ui.scriptresourceattribute(VS.100).aspx"&gt;ScriptResourceAttribute&lt;/a&gt; attribute, but it must match the type name that is used in the client script. In this example, it is set to Answer.&lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;[assembly: System.Web.UI.WebResource(&amp;quot;LocalizingScriptResources.CheckAnswer.js&amp;quot;, &amp;quot;application/x-javascript&amp;quot;)]//用于下载js文件&lt;/p&gt;  &lt;p&gt;[assembly: System.Web.UI.ScriptResource(&amp;quot;LocalizingScriptResources.CheckAnswer.js&amp;quot;, &amp;quot;LocalizingScriptResources.VerificationResources&amp;quot;, &amp;quot;Answer&amp;quot;)]//用于在脚本代码中使用资源（Answer对象）   &lt;table border="1" cellpadding="0"&gt;&lt;tbody&gt;       &lt;tr&gt;         &lt;td valign="bottom"&gt;           &lt;p&gt;&lt;b&gt;&lt;a href="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/2677.clip_5F00_image003_5F00_44C8877C.gif"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="clip_image003" border="0" alt="clip_image003" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/6874.clip_5F00_image003_5F00_thumb_5F00_27563670.gif" width="10" height="10" /&gt;&lt;/a&gt;&lt;/b&gt;&lt;b&gt;Note&lt;/b&gt;&lt;/p&gt;         &lt;/td&gt;       &lt;/tr&gt;        &lt;tr&gt;         &lt;td valign="top"&gt;           &lt;p&gt;The AssemblyInfo.vb file is in the &lt;b&gt;My Project&lt;/b&gt; node of &lt;b&gt;Solution Explorer&lt;/b&gt;. If you do not see any files in the &lt;b&gt;My Project&lt;/b&gt; node, in the &lt;b&gt;Project&lt;/b&gt; menu, click &lt;b&gt;Show All Files&lt;/b&gt;. The AssemblyInfo.cs file is in the &lt;b&gt;Properties&lt;/b&gt; node of &lt;b&gt;Solution Explorer&lt;/b&gt;.&lt;/p&gt;         &lt;/td&gt;       &lt;/tr&gt;     &lt;/tbody&gt;&lt;/table&gt; &lt;/p&gt;  &lt;p&gt;The &lt;b&gt;WebResource&lt;/b&gt; definition must include the default namespace of the assembly and the name of the .js file. The &lt;b&gt;ScriptResource&lt;/b&gt; definition does not include the file name extension or the localized .resx files.&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Build the project.&lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;When compilation finishes, you will have an assembly named LocalizingScriptResources.dll. The JavaScript code in the CheckAnswer.js file and the resources in the two .resx files are embedded in this assembly as resources.&lt;/p&gt;  &lt;p&gt;You will also have an assembly named LocalizingScriptResources.resources.dll (a satellite assembly) that contains the Italian resources for server code.&lt;/p&gt;  &lt;p&gt;&lt;b&gt;&lt;a href="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/0820.clip_5F00_image0012_5F00_74F262F0.gif"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="clip_image001[2]" border="0" alt="clip_image001[2]" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/6378.clip_5F00_image0012_5F00_thumb_5F00_428E8F71.gif" width="1" height="1" /&gt;&lt;/a&gt;&lt;/b&gt;&lt;b&gt; Referencing the Embedded Script and Resources &lt;/b&gt;&lt;/p&gt;  &lt;p&gt;You can now use the assembly in an AJAX-enabled ASP.NET Web site. You will be able to read the .js file and the resource values in client script.   &lt;table border="1" cellpadding="0"&gt;&lt;tbody&gt;       &lt;tr&gt;         &lt;td valign="bottom"&gt;           &lt;p&gt;&lt;b&gt;&lt;a href="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/6862.clip_5F00_image0031_5F00_3B032004.gif"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="clip_image003[1]" border="0" alt="clip_image003[1]" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/4621.clip_5F00_image0031_5F00_thumb_5F00_56A7ABFA.gif" width="10" height="10" /&gt;&lt;/a&gt;&lt;/b&gt;&lt;b&gt;Note&lt;/b&gt;&lt;/p&gt;         &lt;/td&gt;       &lt;/tr&gt;        &lt;tr&gt;         &lt;td valign="top"&gt;           &lt;p&gt;Although you can create the class library project and the Web site in the same Visual Studio solution, in this walkthrough it is not assumed that you are doing this. Having the projects in separate solutions emulates how a control developer and a page developer would work separately. However, for convenience you can create both projects in the same solution and make small adjustments to procedures in the walkthrough.&lt;/p&gt;         &lt;/td&gt;       &lt;/tr&gt;     &lt;/tbody&gt;&lt;/table&gt; &lt;/p&gt;  &lt;p&gt;&lt;b&gt;To reference the embedded script and resources&lt;/b&gt;&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;In Visual Studio, create a new AJAX-enabled Web site.&lt;/li&gt;    &lt;li&gt;Add a Bin folder under the Web site root.&lt;/li&gt;    &lt;li&gt;Add the&lt;b&gt; LocalizingScriptResources.dll&lt;/b&gt; assembly from the class library project to the &lt;b&gt;Bin&lt;/b&gt; folder.&lt;/li&gt; &lt;/ol&gt;  &lt;table border="1" cellpadding="0"&gt;&lt;tbody&gt;     &lt;tr&gt;       &lt;td valign="bottom"&gt;         &lt;p&gt;&lt;b&gt;&lt;a href="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/5707.clip_5F00_image0032_5F00_563B7905.gif"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="clip_image003[2]" border="0" alt="clip_image003[2]" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/5381.clip_5F00_image0032_5F00_thumb_5F00_78930E7E.gif" width="10" height="10" /&gt;&lt;/a&gt;&lt;/b&gt;&lt;b&gt;Note&lt;/b&gt;&lt;/p&gt;       &lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top"&gt;         &lt;p&gt;If you created the class library project and the Web site in the same Visual Studio solution, you can add a reference from the class library project to the Web site. For details, see &lt;a href="http://msdn.microsoft.com/en-us/library/f3st0d45(VS.100).aspx"&gt;How to: Add a Reference to a Visual Studio Project in a Web Site&lt;/a&gt;.&lt;/p&gt;       &lt;/td&gt;     &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;  &lt;ol&gt;   &lt;li&gt;Create a folder in the &lt;b&gt;Bin&lt;/b&gt; folder and give it the name &lt;b&gt;it&lt;/b&gt; (for Italian).&lt;/li&gt;    &lt;li&gt;Add the &lt;b&gt;LocalizingScriptResources.resources.dll&lt;/b&gt; satellite assembly from the &lt;b&gt;it&lt;/b&gt; folder in the &lt;b&gt;LocalizingScriptResources&lt;/b&gt; project to the &lt;b&gt;it&lt;/b&gt; folder in the Web site.&lt;/li&gt;    &lt;li&gt;Add a new ASP.NET Web page to the project. &lt;/li&gt;    &lt;li&gt;Replace the code in the page with the following code: &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;&amp;lt;%@ Page Language=&amp;quot;C#&amp;quot; AutoEventWireup=&amp;quot;true&amp;quot; UICulture=&amp;quot;auto&amp;quot; Culture=&amp;quot;auto&amp;quot; %&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;%@ Register TagPrefix=&amp;quot;Samples&amp;quot; Namespace=&amp;quot;LocalizingScriptResources&amp;quot; Assembly=&amp;quot;LocalizingScriptResources&amp;quot; %&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;script runat=&amp;quot;server&amp;quot;&amp;gt;&lt;/p&gt;  &lt;p&gt;protected void Page_Load(object sender, EventArgs e)&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;if (IsPostBack)&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;System.Threading.Thread.CurrentThread.CurrentUICulture = System.Globalization.CultureInfo.CreateSpecificCulture(selectLanguage.SelectedValue);&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;else&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;try{&lt;/p&gt;  &lt;p&gt;selectLanguage.Items.FindByValue(System.Threading.Thread.CurrentThread.CurrentUICulture.TwoLetterISOLanguageName).Selected = true;&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;catch{&lt;/p&gt;  &lt;p&gt;selectLanguage.Items.FindByValue(“en”).Selected = true;&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;protected void selectLanguage_SelectedIndexChanged(object sender, EventArgs e)&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;System.Threading.Thread.CurrentThread.CurrentUICulture = System.Globalization.CultureInfo.CreateSpecificCulture(selectLanguage.SelectedValue);&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;&amp;lt;/script&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;!DOCTYPE html PUBLIC &amp;quot;-//W3C//DTD XHTML 1.1//EN&amp;quot; &amp;quot;http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd&amp;quot;&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;html &amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;head runat=&amp;quot;server&amp;quot;&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;title&amp;gt;Client Localization Example&amp;lt;/title&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;/head&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;body&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;form id=&amp;quot;form1&amp;quot; runat=&amp;quot;server&amp;quot;&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;asp:DropDownList runat=&amp;quot;server&amp;quot; AutoPostBack=&amp;quot;true&amp;quot; ID=&amp;quot;selectLanguage&amp;quot; OnSelectedIndexChanged=&amp;quot;selectLanguage_SelectedIndexChanged&amp;quot;&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;asp:ListItem Text=&amp;quot;English&amp;quot; Value=&amp;quot;en&amp;quot;&amp;gt;&amp;lt;/asp:ListItem&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;asp:ListItem Text=&amp;quot;Italian&amp;quot; Value=&amp;quot;it&amp;quot;&amp;gt;&amp;lt;/asp:ListItem&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;/asp:DropDownList&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;asp:ScriptManager ID=&amp;quot;ScriptManager1&amp;quot; EnableScriptLocalization=&amp;quot;true&amp;quot; runat=&amp;quot;server&amp;quot;&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;Scripts&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;asp:ScriptReference Assembly=&amp;quot;LocalizingScriptResources&amp;quot; Name=&amp;quot;LocalizingScriptResources.CheckAnswer.js&amp;quot; /&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;/Scripts&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;/asp:ScriptManager&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;div&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;Samples:ClientVerification runat=&amp;quot;server&amp;quot; &amp;gt;&amp;lt;/Samples:ClientVerification&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;/div&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;/form&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;/body&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;/html&amp;gt;&lt;/p&gt;  &lt;p&gt;The control that you created in the LocalizingScriptResources project is included on the page. This control displays two numbers for the user to add and a &lt;a href="http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.textbox(VS.100).aspx"&gt;TextBox&lt;/a&gt; control for the user to enter an answer. It also displays a button that calls the script in the CheckAnswer function when the button is clicked. The CheckAnswer function runs in the browser and displays a localized message that states whether the answer is correct. &lt;/p&gt;  &lt;p&gt;You must set the &lt;a href="http://msdn.microsoft.com/en-us/library/system.web.ui.scriptmanager.enablescriptlocalization(VS.100).aspx"&gt;EnableScriptLocalization&lt;/a&gt; property of the &lt;a href="http://msdn.microsoft.com/en-us/library/system.web.ui.scriptmanager(VS.100).aspx"&gt;ScriptManager&lt;/a&gt; object to &lt;b&gt;true&lt;/b&gt; to enable the &lt;a href="http://msdn.microsoft.com/en-us/library/system.web.ui.scriptmanager(VS.100).aspx"&gt;ScriptManager&lt;/a&gt; control to retrieve localized resources. You must also set the culture and UI culture to &lt;b&gt;&amp;quot;auto&amp;quot; &lt;/b&gt;to display the strings that are based on the browser&amp;#39;s settings. &lt;/p&gt;  &lt;p&gt;The page contains a &lt;a href="http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.dropdownlist(VS.100).aspx"&gt;DropDownList&lt;/a&gt; control that you can use to change the language settings without changing the settings in the browser. When the &lt;a href="http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.dropdownlist.selectedindex(VS.100).aspx"&gt;SelectedIndex&lt;/a&gt; property of the &lt;a href="http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.dropdownlist(VS.100).aspx"&gt;DropDownList&lt;/a&gt; control changes, the &lt;a href="http://msdn.microsoft.com/en-us/library/system.threading.thread.currentuiculture(VS.100).aspx"&gt;CurrentUICulture&lt;/a&gt; property of the &lt;a href="http://msdn.microsoft.com/en-us/library/system.threading.thread.currentthread(VS.100).aspx"&gt;CurrentThread&lt;/a&gt; instance is set to the value that you have selected.&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Run the project.&lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;You will see an addition problem with two randomly generated numbers and a &lt;a href="http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.textbox(VS.100).aspx"&gt;TextBox&lt;/a&gt; control for entering an answer. When you enter an answer and click the &lt;b&gt;Verify Answer&lt;/b&gt; button, you see the response in a message window that tells you whether the answer is correct. By default, the response will be returned in English. &lt;/p&gt;  &lt;p&gt;However, if you have set Italian as your preferred language in the browser, the answer will be in Italian. You can change the language for the response by selecting a language in the &lt;a href="http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.dropdownlist(VS.100).aspx"&gt;DropDownList&lt;/a&gt; control or by changing the preferred language in the browser.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/6765.clip_5F00_image0013_5F00_2D336ABA.gif"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="clip_image001[3]" border="0" alt="clip_image001[3]" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/2654.clip_5F00_image0013_5F00_thumb_5F00_41B8BA38.gif" width="1" height="1" /&gt;&lt;/a&gt; Review &lt;/p&gt;  &lt;p&gt;This walkthrough introduced the concept of embedding a JavaScript file as a resource in an assembly and of including localized strings. The embedded script file can be referenced and accessed in a Web application that contains the assembly. The localized strings will be displayed based on the language setting in the browser or on the language provided by the user.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Walkthrough: Adding Localized Resources to a JavaScript File&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;This walkthrough shows you how to include localized resources in an ECMAScript (JavaScript) file. In this walkthrough the resources are strings. You include localized resources in a JavaScript file when you have created a standalone JavaScript file and when your application must provide different values for different languages and cultures. &lt;/p&gt;  &lt;p&gt;&lt;b&gt;A standalone JavaScript&lt;/b&gt; is not embedded as a resource in an assembly and therefore cannot access values in a resources file. Instead, you include the localized string values directly in the script file. The localized values are retrieved when the script runs in the browser.&lt;/p&gt;  &lt;p&gt;You create a separate script file for each supported language and culture. In each script file, you include an object in &lt;b&gt;JSON format&lt;/b&gt; that contains the localized resources values for that language and culture.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/6371.clip_5F00_image00110_5F00_7A1809CA.gif"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="clip_image001[10]" border="0" alt="clip_image001[10]" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/4721.clip_5F00_image00110_5F00_thumb_5F00_2D9D99DE.gif" width="1" height="1" /&gt;&lt;/a&gt; Prerequisites &lt;/p&gt;  &lt;p&gt;To implement the procedures in this tutorial you need:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Visual Studio or Visual Web Developer 2010 Express.&lt;/li&gt;    &lt;li&gt;An AJAX-enabled ASP.NET Web site.&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&lt;a href="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/0508.clip_5F00_image00111_5F00_7B39C65E.gif"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="clip_image001[11]" border="0" alt="clip_image001[11]" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/7357.clip_5F00_image00111_5F00_thumb_5F00_13C963AF.gif" width="1" height="1" /&gt;&lt;/a&gt; Creating a JavaScript File That Contains Localized Resource Values &lt;/p&gt;  &lt;p&gt;&lt;b&gt;To add resource values to a JavaScript file&lt;/b&gt;&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;In the root directory of the Web site, add a folder named Scripts.&lt;/li&gt;    &lt;li&gt;In the Scripts folder, add a JScript file named CheckAnswer.js, and then add the following code to the file.&lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;Sys.Application.add_load(SetButton);&lt;/p&gt;  &lt;p&gt;function SetButton()&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;$get(&amp;#39;Button1&amp;#39;).value = Answer.Verify;&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;function CheckAnswer()&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;var firstInt = $get(&amp;#39;firstNumber&amp;#39;).innerText;&lt;/p&gt;  &lt;p&gt;var secondInt = $get(&amp;#39;secondNumber&amp;#39;).innerText;&lt;/p&gt;  &lt;p&gt;var userAnswer = $get(&amp;#39;userAnswer&amp;#39;);&lt;/p&gt;  &lt;p&gt;if ((Number.parseLocale(firstInt) + Number.parseLocale(secondInt)) == userAnswer.value)&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;alert(Answer.Correct);&lt;/p&gt;  &lt;p&gt;return true;&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;else&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;alert(Answer.Incorrect);&lt;/p&gt;  &lt;p&gt;return false;&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;Answer={&lt;/p&gt;  &lt;p&gt;&amp;quot;Verify&amp;quot;:&amp;quot;Verify Answer&amp;quot;,&lt;/p&gt;  &lt;p&gt;&amp;quot;Correct&amp;quot;:&amp;quot;Yes, your answer is correct.&amp;quot;,&lt;/p&gt;  &lt;p&gt;&amp;quot;Incorrect&amp;quot;:&amp;quot;No, your answer is incorrect.&amp;quot;&lt;/p&gt;  &lt;p&gt;};&lt;/p&gt;  &lt;p&gt;The script code adds a handler for the &lt;a href="http://msdn.microsoft.com/en-us/library/bb383829(VS.100).aspx"&gt;load&lt;/a&gt; event of the &lt;a href="http://msdn.microsoft.com/en-us/library/bb310856(VS.100).aspx"&gt;Sys.Application&lt;/a&gt; class. The handler sets the button text. Instead of setting the text to a string, it sets the text to a value that is defined in a class named &lt;b&gt;Answer.Verify&lt;/b&gt;. This enables the code to use a localized value.&lt;/p&gt;  &lt;p&gt;The script also contains a function that checks the user&amp;#39;s result for adding two numbers. It uses the &lt;b&gt;alert&lt;/b&gt; function to let the user know whether the answer is correct. As with the button text, the message displayed in the &lt;b&gt;alert&lt;/b&gt; dialog box is set to a localized string value without a postback to the server. &lt;/p&gt;  &lt;p&gt;A type named Answer is used in the script to define the collection of localized values to use in the file. The Answer type is defined in JSON format at the end of the &lt;b&gt;CheckAnswer.js&lt;/b&gt; file.&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;In the Scripts folder, add a JScript file named &lt;b&gt;CheckAnswer.it-IT.js&lt;/b&gt;. Add the following code to the file.&lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;Sys.Application.add_load(SetButton);&lt;/p&gt;  &lt;p&gt;function SetButton()&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;$get(&amp;#39;Button1&amp;#39;).value = Answer.Verify;&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;function CheckAnswer()&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;var firstInt = $get(&amp;#39;firstNumber&amp;#39;).innerText;&lt;/p&gt;  &lt;p&gt;var secondInt = $get(&amp;#39;secondNumber&amp;#39;).innerText;&lt;/p&gt;  &lt;p&gt;var userAnswer = $get(&amp;#39;userAnswer&amp;#39;);&lt;/p&gt;  &lt;p&gt;if ((Number.parseLocale(firstInt) + Number.parseLocale(secondInt)) == userAnswer.value)&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;alert(Answer.Correct);&lt;/p&gt;  &lt;p&gt;return true;&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;else&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;alert(Answer.Incorrect);&lt;/p&gt;  &lt;p&gt;return false;&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;Answer={&lt;/p&gt;  &lt;p&gt;&amp;quot;Verify&amp;quot;:&amp;quot;Verificare la risposta&amp;quot;,&lt;/p&gt;  &lt;p&gt;&amp;quot;Correct&amp;quot;:&amp;quot;Si, la risposta e’ corretta.&amp;quot;,&lt;/p&gt;  &lt;p&gt;&amp;quot;Incorrect&amp;quot;:&amp;quot;No, la risposta e’ sbagliata.&amp;quot;&lt;/p&gt;  &lt;p&gt;};&lt;/p&gt;  &lt;p&gt;This file is identical to the &lt;b&gt;CheckAnswer.js &lt;/b&gt;file except that it contains an Answer type with values in Italian. &lt;/p&gt;  &lt;p&gt;To provide localized text in additional languages, you can create more JavaScript files. The JavaScript code is always the same, but the values that are defined in the Answer type are in different languages. The name of each JavaScript file must include the appropriate language and locale. &lt;/p&gt;  &lt;p&gt;&lt;b&gt;&lt;a href="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/6864.clip_5F00_image00112_5F00_3D4035A0.gif"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="clip_image001[12]" border="0" alt="clip_image001[12]" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/8037.clip_5F00_image00112_5F00_thumb_5F00_51C5851E.gif" width="1" height="1" /&gt;&lt;/a&gt;&lt;/b&gt;&lt;b&gt; Using JavaScript Resource Values in an ASP.NET Page &lt;/b&gt;&lt;/p&gt;  &lt;p&gt;You can now create an ASP.NET Web page that uses the script code that you have created. The page enables you to test the effect of changing a language.&lt;/p&gt;  &lt;p&gt;&lt;b&gt;To use JavaScript resource values in an ASP.NET Web page&lt;/b&gt;&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Create an ASP.NET Web page.&lt;/li&gt;    &lt;li&gt;Replace the content of the Web page with the following markup and code:&lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;&amp;lt;%@ Page Language=&amp;quot;C#&amp;quot; AutoEventWireup=&amp;quot;true&amp;quot; UICulture=&amp;quot;auto&amp;quot; Culture=&amp;quot;auto&amp;quot; %&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;script runat=&amp;quot;server&amp;quot;&amp;gt;&lt;/p&gt;  &lt;p&gt;protected void Page_Load(object sender, EventArgs e)&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;int _firstInt;&lt;/p&gt;  &lt;p&gt;int _secondInt;&lt;/p&gt;  &lt;p&gt;Random random = new Random();&lt;/p&gt;  &lt;p&gt;_firstInt = random.Next(0, 20);&lt;/p&gt;  &lt;p&gt;_secondInt = random.Next(0, 20);&lt;/p&gt;  &lt;p&gt;firstNumber.Text = _firstInt.ToString();&lt;/p&gt;  &lt;p&gt;secondNumber.Text = _secondInt.ToString();&lt;/p&gt;  &lt;p&gt;if (IsPostBack)&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;userAnswer.Text = &amp;quot;&amp;quot;;&lt;/p&gt;  &lt;p&gt;System.Threading.Thread.CurrentThread.CurrentUICulture = System.Globalization.CultureInfo.CreateSpecificCulture(selectLanguage.SelectedValue);&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;else&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;selectLanguage.Items.FindByValue(System.Threading.Thread.CurrentThread.CurrentUICulture.TwoLetterISOLanguageName).Selected = true;&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;protected void selectLanguage_SelectedIndexChanged(object sender, EventArgs e)&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;System.Threading.Thread.CurrentThread.CurrentUICulture = System.Globalization.CultureInfo.CreateSpecificCulture(selectLanguage.SelectedValue);&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;&amp;lt;/script&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;!DOCTYPE html PUBLIC &amp;quot;-//W3C//DTD XHTML 1.1//EN&amp;quot; &amp;quot;http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd&amp;quot;&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;html &amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;head id=&amp;quot;Head1&amp;quot; runat=&amp;quot;server&amp;quot;&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;title&amp;gt;Client Localization Example&amp;lt;/title&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;/head&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;body&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;form id=&amp;quot;form1&amp;quot; runat=&amp;quot;server&amp;quot; &amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;asp:DropDownList runat=&amp;quot;server&amp;quot; AutoPostBack=&amp;quot;true&amp;quot; ID=&amp;quot;selectLanguage&amp;quot; OnSelectedIndexChanged=&amp;quot;selectLanguage_SelectedIndexChanged&amp;quot;&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;asp:ListItem Text=&amp;quot;中D文?&amp;quot; Value=&amp;quot;zh&amp;quot;&amp;gt;&amp;lt;/asp:ListItem&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;asp:ListItem Text=&amp;quot;English&amp;quot; Value=&amp;quot;en&amp;quot;&amp;gt;&amp;lt;/asp:ListItem&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;asp:ListItem Text=&amp;quot;Italian&amp;quot; Value=&amp;quot;it&amp;quot;&amp;gt;&amp;lt;/asp:ListItem&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;/asp:DropDownList&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;asp:ScriptManager ID=&amp;quot;ScriptManager1&amp;quot; EnableScriptLocalization=&amp;quot;true&amp;quot; runat=&amp;quot;server&amp;quot;&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;Scripts&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;asp:ScriptReference Path=&amp;quot;scripts/CheckAnswer.js&amp;quot; ResourceUICultures=&amp;quot;it-IT,zh-CN&amp;quot; /&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;/Scripts&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;/asp:ScriptManager&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;div&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;asp:Label ID=&amp;quot;firstNumber&amp;quot; runat=&amp;quot;server&amp;quot;&amp;gt;&amp;lt;/asp:Label&amp;gt;&lt;/p&gt;  &lt;p&gt;+&lt;/p&gt;  &lt;p&gt;&amp;lt;asp:Label ID=&amp;quot;secondNumber&amp;quot; runat=&amp;quot;server&amp;quot;&amp;gt;&amp;lt;/asp:Label&amp;gt;&lt;/p&gt;  &lt;p&gt;=&lt;/p&gt;  &lt;p&gt;&amp;lt;asp:TextBox ID=&amp;quot;userAnswer&amp;quot; runat=&amp;quot;server&amp;quot;&amp;gt;&amp;lt;/asp:TextBox&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;asp:Button ID=&amp;quot;Button1&amp;quot; runat=&amp;quot;server&amp;quot; OnClientClick=&amp;quot;return CheckAnswer()&amp;quot; /&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;br /&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;asp:Label ID=&amp;quot;labeltest&amp;quot; runat=&amp;quot;server&amp;quot;&amp;gt;&amp;lt;/asp:Label&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;/div&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;/form&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;/body&amp;gt;&lt;/p&gt;  &lt;p&gt;The markup creates a &lt;a href="http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.dropdownlist(VS.100).aspx"&gt;DropDownList&lt;/a&gt; control, two &lt;a href="http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.label(VS.100).aspx"&gt;Label&lt;/a&gt; controls, a &lt;a href="http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.textbox(VS.100).aspx"&gt;TextBox&lt;/a&gt; control, and a &lt;a href="http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.button(VS.100).aspx"&gt;Button&lt;/a&gt; control. The page displays two randomly generated integers and asks the user to add them, and it provides a text box for an answer. When the button is clicked, the JavaScript CheckAnswer function is called. &lt;/p&gt;  &lt;p&gt;The &lt;a href="http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.dropdownlist(VS.100).aspx"&gt;DropDownList&lt;/a&gt; control enables you to change the language settings without changing the settings in the browser. When the &lt;a href="http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.dropdownlist.selectedindex(VS.100).aspx"&gt;SelectedIndex&lt;/a&gt; property of the &lt;a href="http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.dropdownlist(VS.100).aspx"&gt;DropDownList&lt;/a&gt; control changes, the &lt;a href="http://msdn.microsoft.com/en-us/library/system.threading.thread.currentuiculture(VS.100).aspx"&gt;CurrentUICulture&lt;/a&gt; property of the &lt;a href="http://msdn.microsoft.com/en-us/library/system.threading.thread.currentthread(VS.100).aspx"&gt;CurrentThread&lt;/a&gt; instance is set to the value that you have selected.    &lt;table border="1" cellpadding="0"&gt;&lt;tbody&gt;       &lt;tr&gt;         &lt;td valign="bottom"&gt;           &lt;p&gt;&lt;b&gt;&lt;a href="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/6765.clip_5F00_image0025_5F00_236BFF71.gif"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="clip_image002[5]" border="0" alt="clip_image002[5]" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/6371.clip_5F00_image0025_5F00_thumb_5F00_112338AF.gif" width="10" height="10" /&gt;&lt;/a&gt;&lt;/b&gt;&lt;b&gt;Note&lt;/b&gt;&lt;/p&gt;         &lt;/td&gt;       &lt;/tr&gt;        &lt;tr&gt;         &lt;td valign="top"&gt;           &lt;p&gt;For information about how to set culture information for a thread, see &lt;a href="http://msdn.microsoft.com/en-us/library/bz9tc508(VS.100).aspx"&gt;How to: Set the Culture and UI Culture for ASP.NET Web Page Globalization&lt;/a&gt;.&lt;/p&gt;         &lt;/td&gt;       &lt;/tr&gt;     &lt;/tbody&gt;&lt;/table&gt; &lt;/p&gt;  &lt;p&gt;The &lt;a href="http://msdn.microsoft.com/en-us/library/system.web.ui.scriptmanager(VS.100).aspx"&gt;ScriptManager&lt;/a&gt; control includes a reference to the CheckAnswer.js script file. This causes the page to retrieve the CheckAnswer.js file when the page runs. &lt;/p&gt;  &lt;p&gt;The &lt;a href="http://msdn.microsoft.com/en-us/library/system.web.ui.scriptreferencebase.resourceuicultures(VS.100).aspx"&gt;ResourceUICultures&lt;/a&gt; property of the reference is set to &amp;quot;it-IT&amp;quot; to indicate that the Web site contains an Italian version of the script. As a result, the &lt;a href="http://msdn.microsoft.com/en-us/library/system.web.ui.scriptmanager(VS.100).aspx"&gt;ScriptManager&lt;/a&gt; object retrieves the Italian version when you select &amp;quot;Italian&amp;quot; from the &lt;a href="http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.dropdownlist(VS.100).aspx"&gt;DropDownList&lt;/a&gt; control or when you set &amp;quot;Italian&amp;quot; as the default language in the browser.&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Run the page.&lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;You see an addition problem with two randomly generated numbers and a &lt;a href="http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.textbox(VS.100).aspx"&gt;TextBox&lt;/a&gt; control for entering an answer. When you type an answer and click the &lt;b&gt;Verify Answer&lt;/b&gt; button, you see the response in a message window that tells you whether the answer is correct. &lt;/p&gt;  &lt;p&gt;By default, the response is displayed in English. &lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Change the language to Italian by selecting &amp;quot;Italian&amp;quot; from the drop-down list.&lt;/li&gt;    &lt;li&gt;Perform the quiz again. &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;This time, the answer is in Italian&lt;/p&gt;  &lt;p&gt;&lt;a href="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/6864.clip_5F00_image00113_5F00_5395DAE5.gif"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="clip_image001[13]" border="0" alt="clip_image001[13]" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/8015.clip_5F00_image00113_5F00_thumb_5F00_5A48E468.gif" width="1" height="1" /&gt;&lt;/a&gt; Review &lt;/p&gt;  &lt;p&gt;This walkthrough showed how to add localized resource values to a standalone JavaScript file. The localized values are created as objects in JSON format that are part of individual localized JavaScript files. Localized values are displayed by referencing the JSON object instead of by using hard-coded strings. The localized strings are displayed based on the language setting in the browser or on the language setting that is provided by the user.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://community.icburner.com/aggbug.aspx?PostID=1992" width="1" height="1"&gt;</description><category domain="http://community.icburner.com/blogs/vs2010tests/archive/tags/JavaScript/default.aspx">JavaScript</category><category domain="http://community.icburner.com/blogs/vs2010tests/archive/tags/Ajax/default.aspx">Ajax</category></item><item><title>Compact Web Server in Compact Framework</title><link>http://community.icburner.com/blogs/vs2010tests/archive/2009/10/26/compact-web-server-in-compact-framework.aspx</link><pubDate>Mon, 26 Oct 2009 04:29:20 GMT</pubDate><guid isPermaLink="false">7695cfbe-8499-488a-81cc-9a443df3b4ce:1991</guid><dc:creator>革命</dc:creator><slash:comments>0</slash:comments><description>&lt;p&gt;Monday, October 22, 2007 @ 15:42&lt;/p&gt;  &lt;p&gt;Today I want to write about small class library I wrote some times ago. It is the &lt;b&gt;compact web server written in C#&lt;/b&gt;. Class library implements functionality of the single threaded web server, which can run in Windows CE powered system as well as desktop version of Microsoft Windows. Currently only the GET method is supported, but it&amp;#39;s possible to pass query strings and process &amp;#39;em in custom code. Let&amp;#39;s see some examples. &lt;/p&gt;  &lt;p&gt;&lt;b&gt;Configuring web server&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;Configuration for web server is stored in &lt;i&gt;WebServerConfiguration&lt;/i&gt; class. Here it&amp;#39;s possible to setup server root, listening port, IP address etc.. Important thing is the possibility to configure default files like default.html, index.html or other. Do not forget to register MIME types for files that will be handled by the web server. Setting right mime types is necessary for correct response header of the server. &lt;/p&gt;  &lt;p&gt;Special files are those files, that need to be treat in custom method and not just send to the client. &lt;b&gt;CompactWeb&lt;/b&gt; server supports &lt;b&gt;virtual directories&lt;/b&gt; so you can request directory placed outside the server root. &lt;/p&gt;  &lt;p&gt;WebServerConfiguration webConf = new WebServerConfiguration();&lt;/p&gt;  &lt;p&gt;webConf.IPAddress = IPAddress.Any;&lt;/p&gt;  &lt;p&gt;webConf.Port = 80;&lt;/p&gt;  &lt;p&gt;// Folder where the web is stored&lt;/p&gt;  &lt;p&gt;webConf.ServerRoot = @&amp;quot;\Inetpub&amp;quot;;&lt;/p&gt;  &lt;p&gt;webConf.AddDefaultFile(&amp;quot;default.html&amp;quot;);&lt;/p&gt;  &lt;p&gt;webConf.AddMimeType(&amp;quot;.htm&amp;quot;, &amp;quot;text/html&amp;quot;);&lt;/p&gt;  &lt;p&gt;webConf.AddMimeType(&amp;quot;.html&amp;quot;, &amp;quot;text/html&amp;quot;);&lt;/p&gt;  &lt;p&gt;webConf.AddMimeType(&amp;quot;.png&amp;quot;, &amp;quot;image/png&amp;quot;);&lt;/p&gt;  &lt;p&gt;webConf.AddMimeType(&amp;quot;.jpg&amp;quot;, &amp;quot;image/jpg&amp;quot;);&lt;/p&gt;  &lt;p&gt;webConf.AddMimeType(&amp;quot;.gif&amp;quot;, &amp;quot;image/gif&amp;quot;);&lt;/p&gt;  &lt;p&gt;webConf.AddMimeType(&amp;quot;.bmp&amp;quot;, &amp;quot;image/bmp&amp;quot;);&lt;/p&gt;  &lt;p&gt;webConf.AddMimeType(&amp;quot;.cgi&amp;quot;, &amp;quot;text/html&amp;quot;);&lt;/p&gt;  &lt;p&gt;// .cgi files will be special handled&lt;/p&gt;  &lt;p&gt;webConf.AddSpecialFileType(&amp;quot;.cgi&amp;quot;);&lt;/p&gt;  &lt;p&gt;// Register virtual directory&lt;/p&gt;  &lt;p&gt;webConf.AddVirtualDirectory(&amp;quot;photos&amp;quot;, @&amp;quot;\My Documents\Photos&amp;quot;);&lt;/p&gt;  &lt;p&gt;Necessary step is to setup server root physically in the file system. Simply create the folder and put the website in. &lt;/p&gt;  &lt;p&gt;&lt;a href="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/6303.clip_5F00_image002_5F00_08058591.gif"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="clip_image002" border="0" alt="clip_image002" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/2063.clip_5F00_image002_5F00_thumb_5F00_5F46CDEF.gif" width="246" height="325" /&gt;&lt;/a&gt;&lt;a href="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/8030.clip_5F00_image004_5F00_6F559CA6.gif"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="clip_image004" border="0" alt="clip_image004" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/8831.clip_5F00_image004_5F00_thumb_5F00_71922562.gif" width="246" height="325" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Start me up&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;Starting the web server is the easiest thing in whole process. Registering &lt;b&gt;OnLogEvent&lt;/b&gt; is fine to track client connections, response sending and exceptions. &lt;b&gt;OnSpecialFileType&lt;/b&gt; is raised whenever the file registered as special is requested by client. Delegate for this event can handle output to the client. &lt;/p&gt;  &lt;p&gt;webServer = new WebServer(webConf);&lt;/p&gt;  &lt;p&gt;webServer.OnLogEvent += new WebServer.LogEvent(webServer_OnLogEvent);&lt;/p&gt;  &lt;p&gt;webServer.OnSpecialFileType += new WebServer.SpecialFileType(webServer_OnSpecialFileType);&lt;/p&gt;  &lt;p&gt;webServer.Start();&lt;/p&gt;  &lt;p&gt;From here, your server is running and ready to serve all files placed in the server root. &lt;a href="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/1588.clip_5F00_image006_5F00_5EDD2BAB.gif"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;margin-left:0px;border-top:0px;margin-right:0px;border-right:0px;" title="clip_image006" border="0" alt="clip_image006" align="left" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/3731.clip_5F00_image006_5F00_thumb_5F00_3D82A771.gif" width="246" height="325" /&gt;&lt;/a&gt;&lt;a href="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/2654.clip_5F00_image008_5F00_43C97DFF.gif"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;margin-left:0px;border-top:0px;margin-right:0px;border-right:0px;" title="clip_image008" border="0" alt="clip_image008" align="left" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/7853.clip_5F00_image008_5F00_thumb_5F00_6CD41CFB.gif" width="246" height="325" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;b&gt;ASP, PHP, CGI whatever you want&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;If it&amp;#39;s necessary to process some files in special way, you can use delegate to &lt;b&gt;OnSpecialFileType&lt;/b&gt; and take the control over processing. Next piece of code handles file with .cgi extension. It takes the content of the file and replace pattern with parameter &lt;i&gt;userName&lt;/i&gt; passed in the query string. In case that you will call following URL &lt;b&gt;http://127.0.0.1/form.cgi?userNamer=Joshua&lt;/b&gt; the pattern will be replaced with &lt;i&gt;Joshua&lt;/i&gt;. &lt;/p&gt;  &lt;p&gt;void webServer_OnSpecialFileType(CompactWeb.WebRequest webRequest, out IO.Stream outputStream)&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;outputStream = new MemoryStream();&lt;/p&gt;  &lt;p&gt;if (webRequest.FileName == &amp;quot;form.cgi&amp;quot;)&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;// Read the requested file template&lt;/p&gt;  &lt;p&gt;FileStream sourceFile = new FileStream(webRequest.FullPath, FileMode.Open);&lt;/p&gt;  &lt;p&gt;StreamReader streamReader = new StreamReader(sourceFile);&lt;/p&gt;  &lt;p&gt;string response = streamReader.ReadToEnd();&lt;/p&gt;  &lt;p&gt;streamReader.Close();&lt;/p&gt;  &lt;p&gt;sourceFile.Close();&lt;/p&gt;  &lt;p&gt;// Parse query string into NameValueCollection&lt;/p&gt;  &lt;p&gt;NameValueCollection query = WebServer.ParseQueryString(webRequest.QueryString);&lt;/p&gt;  &lt;p&gt;// Replace &amp;lt;%=RESULT%&amp;gt; with the username&lt;/p&gt;  &lt;p&gt;string userName = query[&amp;quot;userName&amp;quot;];&lt;/p&gt;  &lt;p&gt;response = response.Replace(&amp;quot;&amp;lt;%=RESULT%&amp;gt;&amp;quot;, userName);&lt;/p&gt;  &lt;p&gt;// Creat response&lt;/p&gt;  &lt;p&gt;byte[] buffer = Encoding.ASCII.GetBytes(response);&lt;/p&gt;  &lt;p&gt;outputStream.Write(buffer, 0, buffer.Length);&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;&lt;a href="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/2654.clip_5F00_image010_5F00_7CE2EBB2.gif"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="clip_image010" border="0" alt="clip_image010" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/6765.clip_5F00_image010_5F00_thumb_5F00_2344CEFE.gif" width="246" height="325" /&gt;&lt;/a&gt;&lt;a href="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/7851.clip_5F00_image012_5F00_0C858775.gif"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="clip_image012" border="0" alt="clip_image012" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/1104.clip_5F00_image012_5F00_thumb_5F00_19EB9A7B.gif" width="246" height="325" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Download and Conclusion&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;Complete &lt;b&gt;CompactWeb&lt;/b&gt; class library with this sample code is possible to download here &lt;a href="http://bansky.net/blog_stuff/CompactWebServer.zip"&gt;CompactWebServer.zip&lt;/a&gt; . Even if the code is written in compact framework it can be compiled and used with full version of .NET framework. Usage is &lt;b&gt;NOT limited to windows mobile&lt;/b&gt;. Feel free to suggest any ideas and improvements, or change the code for your needs. I believe that you will find this library useful. &lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;h6&gt;&lt;a href="http://blogs.msdn.com/mitsu/archive/2009/07/02/windows-mobile-silverlight-hosting.aspx"&gt;Serving Silverlight Apps from Windows Mobile&lt;/a&gt;&lt;/h6&gt;  &lt;p&gt;For the last Paris mobility briefing, my colleague &lt;a href="http://blogs.msdn.com/pierreca/"&gt;Pierre Cauchois&lt;/a&gt; asked me to co-animate the Coding4Fun session…hard to refuse.&lt;/p&gt;  &lt;p&gt;Even if mobile dev is not my every day work, thanks to the .Net Compact Framework, it’s still .Net programming.&lt;/p&gt;  &lt;p&gt;Here is the scenario:&lt;/p&gt;  &lt;p&gt;You come back home, you have a windows mobile phone wifi capable and you want to quickly get access to your phone pictures from your home network.    &lt;br /&gt;You just activate the Wifi, run my app and then browse to the provided link from any computer on the network.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/mitsu/WindowsLiveWriter/WindowsMobileSilverlighthosting_112BD/image_4.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="clip_image002[5]" border="0" alt="clip_image002[5]" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/3247.clip_5F00_image0025_5F00_2769A6EE.gif" width="244" height="151" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Then a silverlight application is loaded from the phone and you can see any of your pictures.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/mitsu/WindowsLiveWriter/WindowsMobileSilverlighthosting_112BD/image_6.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="clip_image004[5]" border="0" alt="clip_image004[5]" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/1184.clip_5F00_image0045_5F00_3F4AAB0B.gif" width="244" height="218" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Here is how it works:&lt;/p&gt;  &lt;p&gt;I decided to use windows mobile to host a Silverlight application.&lt;/p&gt;  &lt;p&gt;I had just needed a Mobile Web Server that I found &lt;a href="http://bansky.net/blog/2007/10/compact-web-server-in-compact-framework/"&gt;here&lt;/a&gt; (thanks to &lt;a href="http://bansky.net/blog"&gt;Pavel Bánský&lt;/a&gt;). The code is full C# and really small and easy to use. I just had to add cookie support but I will talk about it later.&lt;/p&gt;  &lt;p&gt;Now I have a basic web server hosted on my phone, I will publish some stuff.&lt;/p&gt;  &lt;p&gt;- the main html page containing the silverlight application. I renamed the one provided by Visual Studio to “Default.html” to make it the default page of my web site.&lt;/p&gt;  &lt;p&gt;- the xap file which is the Silverlight application itself.&lt;/p&gt;  &lt;p&gt;- a web service to expose the list of pictures available on my phone. As I had no web service infrastructure available on my very small web server, I have decided to expose a rss feed which is made with just a few lines of Linq to Xml. Exposing pictures on http gives a lot of advantages like getting the benefits of the browser local cache. In this project it’s very useful because the mobile phone does not have a large and powerful bandwidth, so we appreciate not to reload pictures ever time. Now we just need to link some Silverlight Image controls to the pictures urls and the Silverlight image loader will work for us.&lt;/p&gt;  &lt;p&gt;- make the pictures visible. The web server contains a virtual folder feature. I just had to make it point to the local pictures path.&lt;/p&gt;  &lt;p&gt;&lt;u&gt;Linq to Xml rss content creation on server side (Compact Framework):&lt;/u&gt;&lt;/p&gt;  &lt;p&gt;var files = Directory.GetFiles(picturesPath, &amp;quot;*.jpg&amp;quot;);   &lt;br /&gt;XElement response = new XElement(&amp;quot;rss&amp;quot;,    &lt;br /&gt;new XAttribute(&amp;quot;version&amp;quot;, &amp;quot;2.0&amp;quot;),    &lt;br /&gt;new XElement(&amp;quot;channel&amp;quot;,    &lt;br /&gt;new XElement(&amp;quot;title&amp;quot;, &amp;quot;Mobile pictures&amp;quot;),    &lt;br /&gt;new XElement(&amp;quot;description&amp;quot;, &amp;quot;Mobile pictures from my phone&amp;quot;),    &lt;br /&gt;new XElement(&amp;quot;link&amp;quot;, &amp;quot;&amp;quot;),    &lt;br /&gt;(from file in files.Select(f =&amp;gt; Path.GetFileName(f))    &lt;br /&gt;select    &lt;br /&gt;new XElement(&amp;quot;item&amp;quot;,    &lt;br /&gt;new XElement(&amp;quot;title&amp;quot;, file),    &lt;br /&gt;new XElement(&amp;quot;description&amp;quot;, file),    &lt;br /&gt;new XElement(&amp;quot;link&amp;quot;, string.Format(&amp;quot;http://{0}/photos/{1}&amp;quot;,ipAddress,file))    &lt;br /&gt;)    &lt;br /&gt;).ToArray()    &lt;br /&gt;)    &lt;br /&gt;);&lt;/p&gt;  &lt;p&gt;Regarding the client development, I have created a simple Silverlight 3 application (yes I also wanted to play with those new features like 3D and non linear animations).&lt;/p&gt;  &lt;p&gt;The Silverlight application calls the web service, reads the rss content (using Linq to Xml again !) and binds the pictures paths to a listbox. The selected picture is displayed in the biggest part of the window. When you change the selected picture, an animation wipes out the existing one and another is bringing the new one with a 3D effect.&lt;/p&gt;  &lt;p&gt;&lt;u&gt;Analysing rss content with Linq to Xml on client side (Silverlight):&lt;/u&gt;&lt;/p&gt;  &lt;p&gt;var root = XElement.Parse(e.Result);   &lt;br /&gt;var items = root.Element(&amp;quot;channel&amp;quot;).Elements(&amp;quot;item&amp;quot;).Select(i =&amp;gt; i.Element(&amp;quot;link&amp;quot;).Value);    &lt;br /&gt;lb.ItemsSource = items;&lt;/p&gt;  &lt;p&gt;And that’s it !&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/mitsu/WindowsLiveWriter/WindowsMobileSilverlighthosting_112BD/image_8.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="clip_image006[6]" border="0" alt="clip_image006[6]" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/4718.clip_5F00_image0066_5F00_2F3E6D05.gif" width="244" height="172" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Now let’s talk about security. Once again, it’s just a little demo but we can not talk about opening a web server on your phone without talking about security.&lt;/p&gt;  &lt;p&gt;The web server is made to respond to the user for a short time. https is complex and even basic authentication needs credentials on the server side. I have chosen another solution that I found to be more appropriate. In my scenario, the web server is requested by a single user who’s got the phone in his hands. So when a first request comes (no cookie), I am asking for a human validation (MessageBox). Of course during this time the server is stopped. The user just has to validate on the phone and then the server answers and provides an authentication cookie. Next requests will carry the cookie and the user will not have to validate again.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/mitsu/WindowsLiveWriter/WindowsMobileSilverlighthosting_112BD/image_10.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="clip_image008[6]" border="0" alt="clip_image008[6]" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/5775.clip_5F00_image0086_5F00_75BB5D0D.gif" width="244" height="214" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;This remains a really really small demo. We could of course imagine having a more robust web server and some optimizations like thumbnails creation on server side but this was just a test and I hope it gave some interesting ideas to some of you.&lt;/p&gt;  &lt;p&gt;In addition to hosting a Silverlight application on my mobile phone, the funniest was to be able to use .Net both on server and client side (Compact Framework and Silverlight) without using the Windows .Net Framework !&lt;/p&gt;  &lt;p&gt;The source code is attached to this post.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://community.icburner.com/aggbug.aspx?PostID=1991" width="1" height="1"&gt;</description><category domain="http://community.icburner.com/blogs/vs2010tests/archive/tags/Mobile_2C00_+CE/default.aspx">Mobile, CE</category><category domain="http://community.icburner.com/blogs/vs2010tests/archive/tags/Silverlight/default.aspx">Silverlight</category></item><item><title>ASP.NET动态数据查询</title><link>http://community.icburner.com/blogs/vs2010tests/archive/2009/10/26/asp-net-33.aspx</link><pubDate>Mon, 26 Oct 2009 04:21:23 GMT</pubDate><guid isPermaLink="false">7695cfbe-8499-488a-81cc-9a443df3b4ce:1990</guid><dc:creator>革命</dc:creator><slash:comments>0</slash:comments><description>&lt;h1&gt;&lt;b&gt;第1部分 &lt;/b&gt;&lt;/h1&gt;  &lt;p&gt;&lt;b&gt;&lt;/b&gt;Una delle novità presenti nella SP1 di .NET 3.5 sono i Dynamic Data (DD), o meglio ASP.NET Dynamic Data. SP1中。NET 3.5中的一个创新是动态数据（DD）的，或更好的ASP.NET动态数据。 In estrema sintesi i DD consentono di generare un sito web completo partendo da un modello dei dati.在一个总括来说，产生的DD可以从一个数据模型完整的Web站点。 Vi è mai capitato di dover costruire un&amp;#39;applicazione web in poco tempo, niente di eccezionale, solo per poter permettere di fare operazioni di interrogazione e modifica su una sorgente dati?你是否曾经不得不在短期内建立一个Web应用程序的时间，没有什么特别，只是为了能够查询和编辑数据源操作？ &lt;/p&gt;  &lt;p&gt;Bene, i DD sono pensati proprio per questi scenari: si parte da un modello dei dati costruito con LINQ to SQL o Entity Framework (ma non solo..) e su questo, delle pagine aspx fungono da template generici, essendo in grado di capire quali tabelle sono presenti nel modello dei dati, di capire come sono fatte e di visualizzarle così come renderle modificabili.那么，DD是设计正是基于这样的场景：我们从使用LINQ到SQL内置框架或实体数据模型开始（但不仅限于..）在这里，在aspx页面作为通用模板，能够理解哪些表存在于数据模型，以了解他们是如何制作，并显示它们作为使编辑。 Esiste quindi un &lt;b&gt;template&lt;/b&gt; unico (condiviso da tutte le tabelle) per le operazioni tipiche che su queste potremmo fare (interrogazione, modifica etc).因此，有&lt;b&gt;共同的模板&lt;/b&gt; （共享的所有表格的典型操作，我们可以做这个（问题，编辑等））。 &lt;/p&gt;  &lt;p&gt;Un altro aspetto importante riguarda il &lt;b&gt;motore di routing&lt;/b&gt; su cui si basano, che consente di non legare l&amp;#39;url che chiamiamo nel browser per richiedere una specifica pagina a dove la pagina fisica risieda oppure a come questa si chiami.另一个重要方面涉及的&lt;b&gt;路由引擎&lt;/b&gt;所依据的，它允许你不绑定在浏览器中调用的URL来请求一个特定的页面，物理页居住或它是如何调用。 Inoltre è possibile modificare il comportamento del motore di routing tramite delle regole, in un unico punto, senza dover modificare alcunché nelle singole pagine e come queste si richiamino tra di loro.您还可以修改的路由引擎，通过在一个地方的规则的行为，而无需改变任何个人网页，以及如何绘制在一起。 &lt;/p&gt;  &lt;p&gt;Partiamo con un semplice esempio:让我们从一个简单的例子： &lt;/p&gt;  &lt;p&gt;Da Visual Studio 2008 SP1 ( oppure con Visual Web Development Express 2008 SP1) scegliamo uno dei due nuovi template disponibili: Visual Studio 2008的SP1的（或Visual Web开发高速2008 SP1的），我们选择了两个新模板可用1： &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/pietrobr/WindowsLiveWriter/UnosguardoaASP.NETDynamicDataparte1_D279/image_6.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="clip_image002" border="0" alt="clip_image002" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/0508.clip_5F00_image002_5F00_79F5073C.gif" width="501" height="344" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Scegliamo &lt;b&gt;Dynamic Data Web Application&lt;/b&gt; , perché pensiamo di generare il modello dei dati con LINQ to SQL, se volessimo usare Entity Framework dovremmo scegliere Dynamic Data Entities ….选择&lt;b&gt;动态数据Web应用程序，&lt;/b&gt;因为我们使用LINQ生成的模型数据到SQL，实体框架我们，如果我们选择使用动态数据实体.... &lt;/p&gt;  &lt;p&gt;Date ora un rapido sguardo al progetto generato che contiene la cartella &lt;i&gt;DynamicData&lt;/i&gt; , che a sua volta contiene i template che vi dicevo sopra, in particolare guardate la sottocartella &lt;i&gt;PageTemplates&lt;/i&gt; che contiene i template usati dai DD. &lt;a href="http://203.208.37.132/translate_c?hl=zh-CN&amp;amp;sl=it&amp;amp;tl=zh-CN&amp;amp;u=http://msdn.microsoft.com/en-us/library/cc668159.aspx&amp;amp;rurl=translate.google.cn&amp;amp;usg=ALkJrhitLhCob2ccYCZIpRWwB23nlJ5hfg"&gt;Qui trovate una descrizione delle pagine incluse di default&lt;/a&gt; .现在日期在生成的项目中包含的文件夹&lt;i&gt;DynamicData，&lt;/i&gt;又包含了模板，我是说以上的&lt;i&gt;PageTemplates&lt;/i&gt;子文件夹包含模板使用的是副署长看，快看。 &lt;a href="http://203.208.37.132/translate_c?hl=zh-CN&amp;amp;sl=it&amp;amp;tl=zh-CN&amp;amp;u=http://msdn.microsoft.com/en-us/library/cc668159.aspx&amp;amp;rurl=translate.google.cn&amp;amp;usg=ALkJrhitLhCob2ccYCZIpRWwB23nlJ5hfg"&gt;下面是描述网页的默认列入。&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;E&amp;#39; interessante anche il folder &lt;i&gt;FiledTemplate&lt;/i&gt; in cui trovate come viene eseguito il rendering di uno specifico tipo, ad esempio il file Boolean.ascx e Boolean_Edit.ascx contengono il codice che viene generato a runtime tutte le volte che si deve generare la parte di pagina che visualizza una colonna del database di tipo boolean e, come avrete capito, il comportamento cambia se siamo in fase di visualizzazione piuttosto che editing del campo.和&amp;#39;有趣&lt;i&gt;FiledTemplate&lt;/i&gt;的文件夹找到，因为它是提供特定类型，如文件Boolean.ascx和Boolean_Edit.ascx，包含的代码，在运行时每次必须生成的页面部分生成显示类型的布尔数据库列，和，你会看到，该行为的变化，如果我们在观看，而不是编辑领域的过程中。 Quindi, in un unico punto, è stato centralizzato il comportamento per la visualizzazione e la modifica dei singoli campi delle tabelle del database.因此，在一个地方，它是为集中查看和数据库表的各个字段编辑的做法。 Posso modificare il codice qui e vedere le modifiche apportate ogni volta che viene visualizzata una colonna che fa riferimento ad un campo boolean su db, di una qualsiasi pagina che venga renderizzata.我可以更改代码，看看这里的变化每次你看到一个列指的是一个布尔字段分贝的任何呈现网页。 I DD hanno anche un meccanismo che consente di fare un po&amp;#39; il contrario: di specificare cioè che un particolare campo boolean, di una particolare tabella sia visualizzato in modo completamente diverso che dagli altri.该署副署长也有一个机制，做一些&amp;#39;相反：如果是，指定一个特定的布尔字段，一个特定表的方式完全不同于其他显示。 Vedremo meglio questo meccanismo di estendibilità in un altro post.我们将看到在另一职位可扩展性机制。 &lt;/p&gt;  &lt;p&gt;Per ora procediamo oltre e aggiungiamo un modello dei dati basato su LINQ to SQL.现在我们采取进一步行动，向数据模型到SQL LINQ的基础。 Dal menù: Add new Item, quindi scegliamo Linq to SQL Classes, “agganciamo” il nostro database Northwind, o quello che preferite, e senza preoccuparcene troppo facciamo drag &amp;amp; drop di tutte le tabelle, alla fine ci troviamo più o meno nella situazione in figura:从菜单：添加新项，然后选择LINQ to SQL类，连接到我们的Northwind数据库，或任何你喜欢，也不要过于担心拖放到最后，我们或多或少的情况中的所有表数字 &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/pietrobr/WindowsLiveWriter/UnosguardoaASP.NETDynamicDataparte1_D279/image_4.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="clip_image004" border="0" alt="clip_image004" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/4705.clip_5F00_image004_5F00_5500C7E0.gif" width="584" height="304" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Nella figura trovate evidenziati il folder DynamicData e il file del modello dei Dati Northwind.dbml.显示在图DynamicData文件夹和数据模型文件Northwind.dbml。 &lt;/p&gt;  &lt;p&gt;Ora andiamo nel file &lt;b&gt;global.asax&lt;/b&gt; , semplicemente scommentiamo la riga di codice in cui informiamo i DD del nostro modello, “registrandolo” e aggiungendo il DataContext che mi ha creato il designer, NorthwindDataContext , imponendo a true l&amp;#39;attributo &lt;i&gt;ScaffoldAllTables&lt;/i&gt; , che in soldoni dice ai DD di utilizzare tutte le tabelle del mio modello dei dati.现在我们是在&lt;b&gt;Global.asax&lt;/b&gt;文件中去，只需取消注释的代码中，我们告诉我们的模型线的DD，“注册”，并补充说，我创建了DataContext的设计师NorthwindDataContext实施&lt;i&gt;ScaffoldAllTables&lt;/i&gt;属性为true，这soldoni副署长说，使用我的数据模型中的所有表。 E&amp;#39; doveroso ricordare, come il commento nella stessa pagina global.asax ricorda, questa può non essere la cosa migliore da fare, ma per ora, per il mio esempio, può andare.和&amp;#39;我们应该记住，因为在同一页上的global.asax记得评论，这可能不是最好的事，但现在，我的例子，它可以走了。 &lt;/p&gt;  &lt;p&gt;Premendo F5 vediamo la nostra applicazione già bella che fatta.按下F5，看到我们美丽的申请已经作出。 In figura vedete la prima schermata che mostra l&amp;#39;elenco delle tabelle在图片您看到的第一个屏幕，显示表的列表 &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/pietrobr/WindowsLiveWriter/UnosguardoaASP.NETDynamicDataparte1_D279/image_8.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="clip_image006" border="0" alt="clip_image006" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/1172.clip_5F00_image006_5F00_7445FF64.gif" width="429" height="368" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Per renderci conto di quanto sia potente il meccanismo di discovery del modello dei dati usato dai DD, premiamo il link che ci porta alla tabella Products, la pagina list.aspx che viene invocata, è un template completamente generico, è in grado di visualizzare correttamente la tabella Products.为实现由副署长所使用的数据模型，发现有多么强大机制，我们按下连结，使我们的产品表，页面list.aspx被调用是一个完全通用的模板，可以正确显示产品表。 &lt;/p&gt;  &lt;p&gt;Nella seguente figura, ho evidenziato gli aspetti notevoli che i DD ci mettono a disposizione gratuitamente:在未来的数字，我强调说，我们的DD提供免费主要方面： &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/pietrobr/WindowsLiveWriter/UnosguardoaASP.NETDynamicDataparte1_D279/image_10.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="clip_image008" border="0" alt="clip_image008" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/1581.clip_5F00_image008_5F00_7CC95EAE.gif" width="595" height="115" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;I DD si accorgono :我知道副署长： &lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;che la tabella Products ha una relazione di foreign-key con la tabella Category ed invece di mostrarci l&amp;#39;ID della Categoria, ad esempio 1 per il primo prodotto, ci mostra il nome della categoria, cioè Beverages.该产品表有一个外商与分类表键的关系，而不是显示我们的编号，如1类，第一个产品，向我们揭示了类的名称，即饮料。 Potente, no!功能强大，没有！ Lo stesso vale per Supplier.这同样适用于供应商。 &lt;/li&gt;    &lt;li&gt;Mettono a disposizione un menù per fare operazione di filtraggio: guardate Discontinued, Category, Supplier: che è generato dinamicamente in base a quali campi boolean e alle relazioni foreign-key presenti nella tabella prodotti.提供一个菜单做的过滤操作：看停产，分类，供应商，这是动态生成什么布尔字段和外商在表中产品的关键关系的基础。 &lt;/li&gt;    &lt;li&gt;Seguendo i link Edit, Delete e Details si giunge a delle pagine che servono proprio per le operazioni suddette, che ovviamente sono generate a partire dagli altri template, anch&amp;#39;essi generici e adattabili a qualsiasi tabella.通过下面的链接编辑，删除和详细导致的网页是否有这种行动，很明显从其他模板，过于一般化，适应任何表生成。 &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Il tutto finora semplicemente scrivendo una riga di codice nel file global.asax.到目前为止，一切只写一行代码在Global.asax文件中。 &lt;/p&gt;  &lt;p&gt;&lt;b&gt;Il Routing&lt;/b&gt;&lt;b&gt; &lt;/b&gt;&lt;b&gt;路由 &lt;/b&gt;&lt;/p&gt;  &lt;p&gt;Se torniamo al file global.asax, noterete come viene generato l&amp;#39;url per navigare l&amp;#39;applicazione web generata:返回到Global.asax文件中，你会发现如何生成的URL浏览Web应用程序的生成： &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/pietrobr/WindowsLiveWriter/UnosguardoaASP.NETDynamicDataparte1_D279/image_12.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="clip_image010" border="0" alt="clip_image010" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/4721.clip_5F00_image010_5F00_30FD87F5.gif" width="488" height="113" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;L&amp;#39;url viene composto con il nome della tabella e il nome delle action, a cui viene aggiunta l&amp;#39;estensione aspx.网址是组成的表名和行动的名义，这是添加到ASPX。 Ora cos&amp;#39;è l&amp;#39;action ?现在是什么行动？ Possiamo pensare alle action come alle azioni eseguite sulla pagina dall&amp;#39;utente.我们可以把行动对用户执行的行动。 Esiste l&amp;#39;enum &lt;a href="http://203.208.37.132/translate_c?hl=zh-CN&amp;amp;sl=it&amp;amp;tl=zh-CN&amp;amp;u=http://msdn.microsoft.com/en-us/library/system.web.dynamicdata.pageaction.aspx&amp;amp;rurl=translate.google.cn&amp;amp;usg=ALkJrhivtAlhajAm6BqrM5XuwxzdQrQ4Fg"&gt;PageAction&lt;/a&gt; che contiene le action usate di default dai DD.有一个枚举&lt;a href="http://203.208.37.132/translate_c?hl=zh-CN&amp;amp;sl=it&amp;amp;tl=zh-CN&amp;amp;u=http://msdn.microsoft.com/en-us/library/system.web.dynamicdata.pageaction.aspx&amp;amp;rurl=translate.google.cn&amp;amp;usg=ALkJrhivtAlhajAm6BqrM5XuwxzdQrQ4Fg"&gt;PageAction&lt;/a&gt;包含由署长默认使用的行动。 Con un esempio si potrebbe dire che se l&amp;#39;utente clicca sul link Edit, per modificare come è fatto un singolo prodotto, la pagina esegue la relativa action &lt;i&gt;PageAction.Edit&lt;/i&gt; e il motore di routing invoca la corrispondente pagina, nell&amp;#39;esempio sopra sarà dunque la pagina Edit.aspx, che trovate nel folder dei template in Page templates.作为一个例子，我们可以说，如果你在编辑链接编辑点击作为单一产品取得，页面执行其行动&lt;i&gt;PageAction.Edit&lt;/i&gt;和路由引擎调用在上面的例子相应的页面因此将Edit.aspx页面，在页面的模板文件夹中找到模板。 &lt;/p&gt;  &lt;p&gt;Per renderci conto di quanto sia flessibile il motore di routing, possiamo provare ad aggiungere due nuove regole.为了实现灵活的路由引擎如何，我们可以尝试添加两个新的规则。 Le regole seguenti valgono solo sulla tabella “Supplier”.以下规则将只适用于表“供应商”。 &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/pietrobr/WindowsLiveWriter/UnosguardoaASP.NETDynamicDataparte1_D279/image_2.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="clip_image012" border="0" alt="clip_image012" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/6371.clip_5F00_image012_5F00_5E7EA7B8.gif" width="561" height="319" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Attenzione : le regole hanno una precedenza, quindi dobbiamo applicare queste due regole prima di quella presente di default che è più generica.注意：优先的规则，所以我们通过之前申请默认目前一，这是较为笼统的这两个规则。 Questa regola agisce quando scegliamo la tabella Supplier (durante la navigazione ).这条规则并当我们选择供应商的表（在导航）。 In questo caso sia che l&amp;#39;utente scelga di selezionare la lista di tutti i supplier (PageAction.List), che scelga di selezionare il singolo supplier (PageAction.Details), la pagina che la visualizza sarà la ListDetails.aspx (anche questa è una delle 4 pagine presenti di default nel folder Page Templates).在这种情况下，是用户选择，选择的所有供应商名单（PageAction.List），谁选择选择单一供应商（PageAction.Details），在出现的页面将是ListDetails.aspx虽然这（是在4页在网页模板文件夹的默认当前1）。 Nella definizione della regola &lt;a href="http://203.208.37.132/translate_c?hl=zh-CN&amp;amp;sl=it&amp;amp;tl=zh-CN&amp;amp;u=http://msdn.microsoft.com/en-us/library/system.web.dynamicdata.dynamicdataroute.viewname.aspx&amp;amp;rurl=translate.google.cn&amp;amp;usg=ALkJrhjr-H_rywcumykBd78wCMQb2id_kg"&gt;ViewName&lt;/a&gt; è il nome della pagina aspx (senza estensione) che deve farne il rendering.在规则的&lt;a href="http://203.208.37.132/translate_c?hl=zh-CN&amp;amp;sl=it&amp;amp;tl=zh-CN&amp;amp;u=http://msdn.microsoft.com/en-us/library/system.web.dynamicdata.dynamicdataroute.viewname.aspx&amp;amp;rurl=translate.google.cn&amp;amp;usg=ALkJrhjr-H_rywcumykBd78wCMQb2id_kg"&gt;视图名&lt;/a&gt;的定义是aspx页面（没有扩展名），必须使渲染的名称。 Mentre in verde vedete l&amp;#39;url che apparirà nella address bar del browser, che può essere quello che volete, in questo caso ho semplicemente rimosso l&amp;#39;estensione “.aspx” alla fine dell&amp;#39;url.当你看到绿色的网址，在您的浏览器，这可能是你想要的地址栏中，在这种情况下我只是删除了“的。aspx”在结尾。 &lt;/p&gt;  &lt;p&gt;&lt;b&gt;Conclusione&lt;/b&gt;&lt;b&gt; &lt;/b&gt;&lt;b&gt;结论 &lt;/b&gt;&lt;/p&gt;  &lt;p&gt;I DD vanno ad arricchire le funzionalità delle WebForms, offrendo un framework per realizzare applicazioni web data-driven.该署副署长应以丰富的WebForms功能，提供了一个框架，以实现数据驱动的Web应用程序。 In questo post abbiamo visto brevemente come iniziare ad usarli vedendo i principi di base del loro funzionamento.在这个后，我们看到了简要如何开始使用他们看到自己的运作的基本原则。 &lt;/p&gt;  &lt;p&gt;I DD offrono comunque un meccanismo che permette molte forme di &lt;b&gt;personalizzazione&lt;/b&gt; , permettono di usare dei template particolari per fare il rendering di campi specifici di una tabella usando ad esempio i controlli dell&amp;#39; AJAX Control Toolkit o di terze parti ad esempio per selezionare un calendario, oppure uno slider per decidere una quantità numerica.副署长我仍然有一个机制，使各种形式的&lt;b&gt;定制&lt;/b&gt;允许使用的模板，使例如细节渲染表的特定区域使用的控制氏例如AJAX控件工具包或任何第三方选择一个日历，或滑块以选择一个数字量。 Le pagine degli ASP.NET Dynamic Data sono già pensate per sfruttare i controlli ASP.NET AJAX. ASP.NET动态数据的页面已经旨在充分利用的ASP.NET AJAX控件。 &lt;/p&gt;  &lt;p&gt;Altri attributi consentono di impostare delle regole di &lt;b&gt;validazione&lt;/b&gt; sul modello dei dati, ad esempio posso impostare tali regole direttamente sulle proprietà delle classi generate da LINQ to SQL, creando delle &lt;i&gt;partial class&lt;/i&gt; .其他属性允许您设置数据&lt;b&gt;验证&lt;/b&gt;规则模式，为举例来说，我可以设置这些规则直接生成的由LINQ到SQL类的属性，创建&lt;i&gt;部分类。&lt;/i&gt; Questo meccanismo consente di accentrare le regole di validazione, che poi “fluiscono” nella UI e valgono in qualsiasi pagina web si faccia riferimento a quella specifica classe...这种机制使集中的验证规则，然后“流”的用户界面，并且在任何网页你指的是特定类的有效... &lt;/p&gt;  &lt;p&gt;Spero di avere stuzzicato la vostra curiosità , almeno per chi non ha ancora avuto modo di provare i nuovi ASP.NET Dynamic Data.我希望我已经激起了您的好奇心，至少对那些谁尚未有机会尝试新的ASP.NET动态数据。 &lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;h1&gt;&lt;b&gt;第2部分&lt;/b&gt;&lt;/h1&gt;  &lt;p&gt;Nel &lt;a href="http://203.208.37.132/translate_c?hl=zh-CN&amp;amp;sl=it&amp;amp;tl=zh-CN&amp;amp;u=http://blogs.msdn.com/pietrobr/archive/2008/09/22/uno-sguardo-a-asp-net-dynamic-data-parte-1.aspx&amp;amp;rurl=translate.google.cn&amp;amp;usg=ALkJrhhUGO-LyxHOxX_RPEabqIM3KUC7Xg"&gt;primo post di questa serie&lt;/a&gt; abbiamo visto come realizzare una prima applicazione con ASP.NET Dynamic Data (DD).在&lt;a href="http://203.208.37.132/translate_c?hl=zh-CN&amp;amp;sl=it&amp;amp;tl=zh-CN&amp;amp;u=http://blogs.msdn.com/pietrobr/archive/2008/09/22/uno-sguardo-a-asp-net-dynamic-data-parte-1.aspx&amp;amp;rurl=translate.google.cn&amp;amp;usg=ALkJrhhUGO-LyxHOxX_RPEabqIM3KUC7Xg"&gt;这个系列&lt;/a&gt; ，我们看到如何与ASP.NET动态数据（DD）的首次申请&lt;a href="http://203.208.37.132/translate_c?hl=zh-CN&amp;amp;sl=it&amp;amp;tl=zh-CN&amp;amp;u=http://blogs.msdn.com/pietrobr/archive/2008/09/22/uno-sguardo-a-asp-net-dynamic-data-parte-1.aspx&amp;amp;rurl=translate.google.cn&amp;amp;usg=ALkJrhhUGO-LyxHOxX_RPEabqIM3KUC7Xg"&gt;的第一篇文章&lt;/a&gt; 。 Come dicevo i DD sono pensati per scenari di rapida prototipazione, dove con poco realizziamo un sito completo partendo dalla basedati.正如我所说的DD方案是用于快速原型，所设计的，只有建立一个网站，以完成该数据库的一部分。 Ci tengono a ricordare che questa è solo una possibilità in più, non in meno, possiamo naturalmente partire da zero usando WebForms o, quando sarà rilasciato, ASP.NET MVC e in base ai gusti scrivere più o meno codice oppure optare per un modello piuttosto che per l&amp;#39;altro.我们必须强调，这只是一次机会更多而不是更少，当然，我们可以从头开始使用的WebForms或者，当它被释放，ASP.NET MVC的，和您的口味或多或少不同的代码编写或选择一个模式，而对其他。 &lt;/p&gt;  &lt;p&gt;Nonostante siano pensati per scenari RAD, però, i DD danno una buona possibilità di personalizzazione: in questo post vedremo come:虽然他们是专为RAD公司的情况，但是，副署长给出了一个定制的机会：我们将看到一个职位： &lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Esporre solo alcune tabelle只有少数几个公开表 &lt;/li&gt;    &lt;li&gt;Visualizzare o meno le colonne delle tabelle esposte显示或隐藏的表列集 &lt;/li&gt;    &lt;li&gt;Personalizzare il comportamento di visualizzazione delle colonne自定义栏的行为展示 &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&lt;b&gt;Quali tabelle esporre&lt;/b&gt;&lt;b&gt;展出的表 &lt;/b&gt;&lt;/p&gt;  &lt;p&gt;Usando l&amp;#39;attributo &lt;i&gt;scaffoldAllTables&lt;/i&gt; nel global.asax abbiamo infatti esposto tutte le tabelle del nostro db.使用属性&lt;i&gt;scaffoldAllTables&lt;/i&gt; global.asax中，实际上我们都暴露在我们的分贝表。 Potremmo, invece, operare selettivamente impostando a false tale attributo e andando a abilitare la/le singole tabelle.我们可以，不过，操作选择地设置此属性为false，将启用/单个表。 Per ogni tabella su db, LINQ to SQL, ha creato una classe &lt;i&gt;partial&lt;/i&gt; , che possiamo vedere nel codice del file .dbml.对于每个数据库表中，LINQ to SQL中，创造了一个&lt;i&gt;局部&lt;/i&gt;类，我们可以看到代码文件。Dbml。 Vediamo ora proprio come estendere queste classi, aggiungiamo un nuovo file Order.cs , che definisce una nuova classe parziale con qualche attributo in più, come mostrato nel seguito:现在让我们看看是如何将这些类，我们添加一个新的文件Order.cs，它定义了另外一些属性一类新的部分，如下所示： &lt;/p&gt;  &lt;p&gt;&lt;a href="https://blogs.msdn.com/blogfiles/pietrobr/WindowsLiveWriter/UnosguardoaASP.NETDynamicDataparte2_9882/image_2.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="clip_image017" border="0" alt="clip_image017" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/6378.clip_5F00_image017_5F00_2E575CF5.gif" width="388" height="115" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Il nuovo namespace &lt;i&gt;System.ComponentModel.DataAnnotation&lt;/i&gt; consente di usare l&amp;#39;attributo &lt;i&gt;ScaffoldTalble&lt;/i&gt; , con cui possiamo rendere o meno visibile la tabella ai DD.新的命名空间&lt;i&gt;System.ComponentModel.DataAnnotation&lt;/i&gt;让你使用属性&lt;i&gt;ScaffoldTalble，&lt;/i&gt;这使我们可以使表或不可见的副署长。 Quindi nel nostro caso abbiamo impostato l&amp;#39;attributo &lt;i&gt;scaffoldAllTables&lt;/i&gt; in global.asax a false, mentre abbiamo impostato per la classe Order (e anche Product ) l&amp;#39;attributo &lt;i&gt;ScaffoldTable&lt;/i&gt; a &lt;b&gt;true&lt;/b&gt; .因此，在我们的情况下，我们将此属性设置为在Global.asax虚假&lt;i&gt;scaffoldAllTables，&lt;/i&gt;虽然我们的Order类的集合（产品&lt;i&gt;）ScaffoldTable&lt;/i&gt;属性设置&lt;b&gt;为true。&lt;/b&gt; Se lanciamo l&amp;#39;applicazione ora vedremo “scovate” dai DD due tabelle, come in figura:如果我们运行应用程序，我们将看到“刷新了由副署长”两个表中的图片，如下： &lt;/p&gt;  &lt;p&gt;&lt;a href="https://blogs.msdn.com/blogfiles/pietrobr/WindowsLiveWriter/UnosguardoaASP.NETDynamicDataparte2_9882/image_4.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="clip_image019" border="0" alt="clip_image019" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/8037.clip_5F00_image019_5F00_29E0DC2E.gif" width="175" height="177" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Controllare le colonne che vengono esposte&lt;/b&gt;&lt;b&gt;检查列曝光 &lt;/b&gt;&lt;/p&gt;  &lt;p&gt;Se andiamo a vedere le colonne della tabella Orders, cliccando sul link, notiamo che sono presenti tutte le colonne definite nella tabella, nella figura vedete evidenziata anche la colonna shippedDate, che andremo a modificare nel seguito:如果我们在订单表列，点击链接看，注意，都是在表中定义的列，也可以看到图片列发货证明，我们要改变如下： &lt;/p&gt;  &lt;p&gt;&lt;a href="https://blogs.msdn.com/blogfiles/pietrobr/WindowsLiveWriter/UnosguardoaASP.NETDynamicDataparte2_9882/image_8.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="clip_image021" border="0" alt="clip_image021" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/8831.clip_5F00_image021_5F00_1BA2633E.gif" width="243" height="59" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Se per qualche ragione non volessimo visualizzarla, ecco che possiamo operare sempre sulla classe parziale precedentemente definita, aggiungendo un attributo &lt;i&gt;ScaffoldColumn&lt;/i&gt; , dal comportamento intuitivo, come mostrato in figura:如果由于某种原因，我们希望看到，在这里我们可以经常操作前面定义的部分类，增加一个属性&lt;i&gt;ScaffoldColumn，&lt;/i&gt;直观的行为，如图所示 &lt;/p&gt;  &lt;p&gt;&lt;a href="https://blogs.msdn.com/blogfiles/pietrobr/WindowsLiveWriter/UnosguardoaASP.NETDynamicDataparte2_9882/image_10.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="clip_image023" border="0" alt="clip_image023" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/3632.clip_5F00_image023_5F00_5042BF79.gif" width="475" height="238" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Questa volta abbiamo dovuto scrivere un po&amp;#39; di codice in più (bene :-)), definire un &lt;i&gt;MetadataType&lt;/i&gt; , una classe nella quale poi definiamo un po&amp;#39; il comportamento relativo alla colonna ShippedDate.这一次，我们写了一个小的额外代码（以及:-)),定义&lt;i&gt;MetadataType，&lt;/i&gt;那么我们定义一个类，其中一些的行为为列发货。 Il comportamento, a meno di errori :-), è quello atteso: se lanciamo il sito e andiamo nella tabella Order, non vederemo più&amp;#160; la colonnaShippedDate, l&amp;#39;attributo in questione, infatti, ha detto ai DD di non visualizzarlo più.的行为，减少错误:-)，预计：如果我们推出该网站，我们去议事程序表，不再colonnaShippedDate&amp;#39;ll看到问题中的属性，其实，不看副署长说了。 Ometto l&amp;#39;immagine, potete immaginare …省略了图像，你能想象... &lt;/p&gt;  &lt;p&gt;&lt;b&gt;Controlliamo il comportamento delle colonne&lt;/b&gt;&lt;b&gt;我们监察列行为 &lt;/b&gt;&lt;/p&gt;  &lt;p&gt;Il comportamento in fase di visualizzazione e modifica dei singoli campi della tabella è definito, come abbiamo visto nel primo post, dai template che si trovano nella directory &lt;i&gt;DynamicData\FieldTemplate&lt;/i&gt; , dove trovate come viene visualizzato ogni campo di uno specifico tipo: guardate ad esempio il codice di Boolean.ascx e Boolean_Edit.ascx.表中的阅读和各领域的编辑时间行为的定义，因为我们是在后看到的，从模板目录下找到&lt;i&gt;DynamicData \ FieldTemplate，&lt;/i&gt;你会发现，因为它是显示每一个特定类型的字段，例如：看看代码Boolean.ascx和Boolean_Edit.ascx。 Ora, se volessi modificare come vengono visualizzati i campi di uno specifico tipo di &lt;b&gt;tutte le tabelle&lt;/b&gt; potrei modificare questi template, ma se volessi operare solo sul &lt;b&gt;singolo campo&lt;/b&gt; (ShippedDate ad esempio) di una &lt;b&gt;specifica tabella&lt;/b&gt; (Orders) potrei (come ho fatto) sfruttare alcuni meccanismi di estendibilità offerti dai DD.现在，如果我想改变显示领域的&lt;b&gt;所有表&lt;/b&gt;我可以改变这些模板的具体类型，但如果我想经营&lt;b&gt;一个字段&lt;/b&gt; （如发货&lt;b&gt;特定表&lt;/b&gt; （Orders））不仅可以（像我一样）利用由副署长提供的可扩展性的一些机制。 Guardate il pezzo di codice qui di seguito:看看下面的代码片： &lt;/p&gt;  &lt;p&gt;&lt;a href="https://blogs.msdn.com/blogfiles/pietrobr/WindowsLiveWriter/UnosguardoaASP.NETDynamicDataparte2_9882/image_12.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="clip_image025" border="0" alt="clip_image025" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/7532.clip_5F00_image025_5F00_398377F0.gif" width="580" height="110" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;In questo caso sto usando l&amp;#39;attributo &lt;a href="http://203.208.37.132/translate_c?hl=zh-CN&amp;amp;sl=it&amp;amp;tl=zh-CN&amp;amp;u=http://msdn.microsoft.com/en-us/library/system.componentmodel.dataannotations.datatypeattribute.displayformat.aspx&amp;amp;rurl=translate.google.cn&amp;amp;usg=ALkJrhiaqxATkTZq2QOXYhxF4mjPiHnqRQ"&gt;&lt;i&gt;DisplayFormat&lt;/i&gt;&lt;/a&gt; per definire il formato di come deve essere visualizzato il campo in questione (la ShippedDate), in questo caso è una data che verrà visualizzata nel formato mostrato in figura.在这种情况下我使用的属性&lt;a href="http://203.208.37.132/translate_c?hl=zh-CN&amp;amp;sl=it&amp;amp;tl=zh-CN&amp;amp;u=http://msdn.microsoft.com/en-us/library/system.componentmodel.dataannotations.datatypeattribute.displayformat.aspx&amp;amp;rurl=translate.google.cn&amp;amp;usg=ALkJrhiaqxATkTZq2QOXYhxF4mjPiHnqRQ"&gt;&lt;i&gt;DisplayFormat&lt;/i&gt;&lt;/a&gt;界定如何字段应显示在问题（发货），在这种情况下，是一个将在显示格式显示的日期格式。 Inoltre grazie all&amp;#39;attributo &lt;a href="http://203.208.37.132/translate_c?hl=zh-CN&amp;amp;sl=it&amp;amp;tl=zh-CN&amp;amp;u=http://msdn.microsoft.com/en-us/library/system.web.dynamicdata.metacolumn.uihint.aspx&amp;amp;rurl=translate.google.cn&amp;amp;usg=ALkJrhi2zPhcm6-QxyPhu9DckopEcGUSdw"&gt;UIHint&lt;/a&gt; sto indicando ai DD di non usare il template di default per il rendering dell&amp;#39;attributo, ma ho creato un nuovo field template che utilizza il controllo Calendar dell&amp;#39; &lt;a href="http://203.208.37.132/translate_c?hl=zh-CN&amp;amp;sl=it&amp;amp;tl=zh-CN&amp;amp;u=http://asp.net/ajax/ajaxcontroltoolkit/samples/&amp;amp;rurl=translate.google.cn&amp;amp;usg=ALkJrhiLPx3-9mK818mzQR2zixYddusEpA"&gt;AJAX Control Toolkit&lt;/a&gt; .此外，该属性&lt;a href="http://203.208.37.132/translate_c?hl=zh-CN&amp;amp;sl=it&amp;amp;tl=zh-CN&amp;amp;u=http://msdn.microsoft.com/en-us/library/system.web.dynamicdata.metacolumn.uihint.aspx&amp;amp;rurl=translate.google.cn&amp;amp;usg=ALkJrhi2zPhcm6-QxyPhu9DckopEcGUSdw"&gt;UIHint&amp;#39;m&lt;/a&gt;感谢指向副署长不使用默认的模板渲染属性，但我创建了一个新的模板字段，使用Calendar控件氏&lt;a href="http://203.208.37.132/translate_c?hl=zh-CN&amp;amp;sl=it&amp;amp;tl=zh-CN&amp;amp;u=http://asp.net/ajax/ajaxcontroltoolkit/samples/&amp;amp;rurl=translate.google.cn&amp;amp;usg=ALkJrhiLPx3-9mK818mzQR2zixYddusEpA"&gt;AJAX控件工具包。&lt;/a&gt; Non vi mostro il codice che ho usato per la personalizzazione del controllo, che non è molto, lo sto finendo di preparare per la sessione dei &lt;a href="http://203.208.37.132/translate_c?hl=zh-CN&amp;amp;sl=it&amp;amp;tl=zh-CN&amp;amp;u=http://www.microsoft.com/italy/eventi/days/technical.mspx&amp;amp;rurl=translate.google.cn&amp;amp;usg=ALkJrhhRBPn2ff25L5wXgUZy2H63l9errg"&gt;Microsoft Days 08&lt;/a&gt; .不显示的代码，我用自定义的控制，这不是很多，我跑出来准备&lt;a href="http://203.208.37.132/translate_c?hl=zh-CN&amp;amp;sl=it&amp;amp;tl=zh-CN&amp;amp;u=http://www.microsoft.com/italy/eventi/days/technical.mspx&amp;amp;rurl=translate.google.cn&amp;amp;usg=ALkJrhhRBPn2ff25L5wXgUZy2H63l9errg"&gt;微软天08&lt;/a&gt;届会议&lt;a href="http://203.208.37.132/translate_c?hl=zh-CN&amp;amp;sl=it&amp;amp;tl=zh-CN&amp;amp;u=http://www.microsoft.com/italy/eventi/days/technical.mspx&amp;amp;rurl=translate.google.cn&amp;amp;usg=ALkJrhhRBPn2ff25L5wXgUZy2H63l9errg"&gt;。&lt;/a&gt; Il risultato visualizzato è il seguente:结果显示如下： &lt;/p&gt;  &lt;p&gt;&lt;a href="https://blogs.msdn.com/blogfiles/pietrobr/WindowsLiveWriter/UnosguardoaASP.NETDynamicDataparte2_9882/image_14.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="clip_image027" border="0" alt="clip_image027" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/2161.clip_5F00_image027_5F00_5FE55B3B.gif" width="213" height="205" /&gt;&lt;/a&gt;    &lt;br /&gt;Dove si nota il calendar in fase di editing della colonna ShippedDate.如果您发现在列发货编辑日历。 &lt;/p&gt;  &lt;p&gt;&lt;b&gt;Conclusione&lt;/b&gt;&lt;b&gt;结论 &lt;/b&gt;&lt;/p&gt;  &lt;p&gt;In questo post avete visto come utilizzare alcune tecniche per personalizzare il comportamento di default dei DD, potendo non solo abilitare\disabilitare specifiche tabelle “scovate” dal runtime, ma anche personalizzando il singolo comportamento di un singolo campo di una specifica tabella, aprendo di fatto a molteplici utilizzi.在这个后你看到了如何使用一些技术，自定义默认行为的DD，他们不仅可以启用\禁用特定表“冲出来”的运行，而且自定义一个字段表在特定的个人行为，铺路的事实多种用途。 I DD sono, in oltre, già compatibili con ASP.NET AJAX e anche con l&amp;#39;AJAX Control Toolkit, non ultimo potreste anche voler utilizzare controlli di terze parti per specifiche esigenze….该署副署长的，此外，已与ASP.NET AJAX兼容，并与AJAX控件工具包，而不是至少你可能也想使用特定需要的第三方控制.... insomma non male, vero?在短，不坏，不是吗？ &lt;/p&gt;  &lt;h5&gt;&lt;strong&gt;链接&lt;/strong&gt;&lt;/h5&gt;  &lt;p&gt;&lt;a href="http://203.208.37.132/translate_c?hl=zh-CN&amp;amp;sl=it&amp;amp;tl=zh-CN&amp;amp;u=http://msdn.microsoft.com/en-us/library/cc488545.aspx&amp;amp;rurl=translate.google.cn&amp;amp;usg=ALkJrhh6roZaQzQCQbPJpbL7ztt4ZbB4XQ"&gt;MSDN library ASP.NET Dynamic Data&lt;/a&gt; &lt;a href="http://203.208.37.132/translate_c?hl=zh-CN&amp;amp;sl=it&amp;amp;tl=zh-CN&amp;amp;u=http://msdn.microsoft.com/en-us/library/cc488545.aspx&amp;amp;rurl=translate.google.cn&amp;amp;usg=ALkJrhh6roZaQzQCQbPJpbL7ztt4ZbB4XQ"&gt;MSDN库ASP.NET动态数据&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://203.208.37.132/translate_c?hl=zh-CN&amp;amp;sl=it&amp;amp;tl=zh-CN&amp;amp;u=http://www.asp.net/dynamicdata/&amp;amp;rurl=translate.google.cn&amp;amp;usg=ALkJrhiaL0RKZ-7dhor4DkRtogVBfbfGsw"&gt;www.asp.net/dynamicdata/&lt;/a&gt; &lt;a href="http://203.208.37.132/translate_c?hl=zh-CN&amp;amp;sl=it&amp;amp;tl=zh-CN&amp;amp;u=http://www.asp.net/dynamicdata/&amp;amp;rurl=translate.google.cn&amp;amp;usg=ALkJrhiaL0RKZ-7dhor4DkRtogVBfbfGsw"&gt;www.asp.net/dynamicdata/&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://community.icburner.com/aggbug.aspx?PostID=1990" width="1" height="1"&gt;</description></item><item><title>Sharepoint 2010概述开发</title><link>http://community.icburner.com/blogs/vs2010tests/archive/2009/10/26/sharepoint-2010.aspx</link><pubDate>Mon, 26 Oct 2009 04:13:06 GMT</pubDate><guid isPermaLink="false">7695cfbe-8499-488a-81cc-9a443df3b4ce:1989</guid><dc:creator>革命</dc:creator><slash:comments>0</slash:comments><description>&lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;h3&gt;第1部分&lt;/h3&gt;  &lt;p&gt;SharePoint 2010 è stato da poco prensentato al pubblico per la prima volta.共享点2010年刚刚首次prensentato公众。 Ho deciso di raccontarvi un po&amp;#39; le novita che saranno presenti in questa release, poichè di sicuro interesse per molti sviluppattori web e, mi aspetto, sempre più nel prossimo fututo.我决定告诉你一个小&amp;#39;的创新是本新闻稿中，利益关系的许多sviluppattori网站，我希望越来越多的在未来fututo。 &lt;/p&gt;  &lt;p&gt;La beta di SharePoint sarà disponibile a novembre, mentre da poco è già disponibilie la beta 2 di Visual Studio 2010 per i sottoscrittori MSDN.测试版的SharePoint将在11月，但最近已经提供的Visual Studio 2010测试版2为MSDN订户。 &lt;/p&gt;  &lt;p&gt;Per una overview della novità annunciate per SharePoint 2010 leggete il &lt;a href="http://203.208.37.132/translate_c?hl=zh-CN&amp;amp;sl=it&amp;amp;tl=zh-CN&amp;amp;u=http://blogs.msdn.com/sharepoint/archive/2009/10/19/sharepoint-2010.aspx&amp;amp;rurl=translate.google.cn&amp;amp;usg=ALkJrhiMc792eCEALHPOy9bfaMIfkabCXw"&gt;post di Jeff Teper&lt;/a&gt; , nei prossimi post cercherò di raccontare le novità più importanti per gli sviluppatori web.对于这一消息公布的SharePoint概述2010年，经过&lt;a href="http://203.208.37.132/translate_c?hl=zh-CN&amp;amp;sl=it&amp;amp;tl=zh-CN&amp;amp;u=http://blogs.msdn.com/sharepoint/archive/2009/10/19/sharepoint-2010.aspx&amp;amp;rurl=translate.google.cn&amp;amp;usg=ALkJrhiMc792eCEALHPOy9bfaMIfkabCXw"&gt;从杰夫泰珀后&lt;/a&gt;的下一个职位&lt;a href="http://203.208.37.132/translate_c?hl=zh-CN&amp;amp;sl=it&amp;amp;tl=zh-CN&amp;amp;u=http://blogs.msdn.com/sharepoint/archive/2009/10/19/sharepoint-2010.aspx&amp;amp;rurl=translate.google.cn&amp;amp;usg=ALkJrhiMc792eCEALHPOy9bfaMIfkabCXw"&gt;，&lt;/a&gt;我会尽量叙述了Web开发最重要的新功能。 &lt;/p&gt;  &lt;p&gt;&lt;b&gt;Sviluppo in Windows 7 e Windows Vista SP1&lt;/b&gt;&lt;b&gt;在Windows 7和Windows Vista SP1的发展 &lt;/b&gt;&lt;/p&gt;  &lt;p&gt;Il nuovo SharePoint 2010 supporterà solo l&amp;#39;archittettura a 64-bit, scelta che va a vantaggio di una maggiore scalabilità del prodotto grazie alla possibilità di sfruttare al meglio la memoria.在新的SharePoint 2010只支持64位架构的选择，是为增加产品的可扩展性利于通过利用记忆能力。 &lt;/p&gt;  &lt;p&gt;La novità più importante è che potrà essere instato, solo a scopo di sviluppo e non per la produzione, su macchine client a 64 bit, in partricolare su &lt;b&gt;Windows 7 e Vista SP1&lt;/b&gt; .最重要的是，只能用于发展目的，而不是用于生产，64中&lt;b&gt;的&lt;/b&gt; Windows &lt;b&gt;7&lt;/b&gt;&lt;b&gt;和Vista SP1&lt;/b&gt; partricolare位客户机统局&lt;b&gt;。&lt;/b&gt; Potrete installare sia &lt;a href="http://203.208.37.132/translate_c?hl=zh-CN&amp;amp;sl=it&amp;amp;tl=zh-CN&amp;amp;u=http://msdn.microsoft.com/en-us/library/ee539826(office.14).aspx&amp;amp;rurl=translate.google.cn&amp;amp;usg=ALkJrhjug-x1yAMErBx4FMM8S2vT5jtfxQ"&gt;SharePoint Foundation&lt;/a&gt; 2010, che &lt;a href="http://203.208.37.132/translate_c?hl=zh-CN&amp;amp;sl=it&amp;amp;tl=zh-CN&amp;amp;u=http://msdn.microsoft.com/en-us/library/ee557323(office.14).aspx&amp;amp;rurl=translate.google.cn&amp;amp;usg=ALkJrhjVIXt7veoA284bMgNeiu1EZwFaUA"&gt;SharePoint Server 2010&lt;/a&gt; in locale sulla macchina in cui avete VS 2010.您可以安装这两个&lt;a href="http://203.208.37.132/translate_c?hl=zh-CN&amp;amp;sl=it&amp;amp;tl=zh-CN&amp;amp;u=http://msdn.microsoft.com/en-us/library/ee539826(office.14).aspx&amp;amp;rurl=translate.google.cn&amp;amp;usg=ALkJrhjug-x1yAMErBx4FMM8S2vT5jtfxQ"&gt;基金会，共享点&lt;/a&gt; &lt;a href="http://203.208.37.132/translate_c?hl=zh-CN&amp;amp;sl=it&amp;amp;tl=zh-CN&amp;amp;u=http://msdn.microsoft.com/en-us/library/ee557323(office.14).aspx&amp;amp;rurl=translate.google.cn&amp;amp;usg=ALkJrhjVIXt7veoA284bMgNeiu1EZwFaUA"&gt;2010，SharePoint服务器2010年&lt;/a&gt;在本地计算机上，您有队2010年。 &lt;/p&gt;  &lt;p&gt;&lt;b&gt;Visual Studio 2010 SharePoint Tool&lt;/b&gt;&lt;b&gt;共享点的Visual Studio 2010工具 &lt;/b&gt;&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Visual Studio 2010&lt;/b&gt; diventa lo strumento principale per lo sviluppo su SharePoint. &lt;b&gt;的Visual Studio 2010年&lt;/b&gt;就成为SharePoint开发的主要工具。 Appena installerete&amp;#160; VS 2010 beta 2 troverete molti &lt;b&gt;nuovi template di progetto&lt;/b&gt; (oltre che numerosi nuovi project item) per SharePoint 2010.刚刚安装队2010 Beta 2的引入了很多&lt;b&gt;新的项目模板&lt;/b&gt; （以及几个新的工程项目）用于SharePoint 2010。 Nella schermata seguente potete averne un&amp;#39;idea:在接下来的屏幕上，您可以有一个想法： &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/pietrobr/WindowsLiveWriter/SharePoint2010OverviewperDeveloper_A977/image_2.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="clip_image002" border="0" alt="clip_image002" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/0820.clip_5F00_image002_5F00_2D594F97.gif" width="461" height="427" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Lo sviluppo per SharePoint con Visual Studio 2010 si semplifica molto, infatti non solo potrete sviluppare su un sistema operativo client una progetto di tipo Visual Web Part, sfruttando l&amp;#39;IDE di Visual Studio 2010, ma di questo verrà creato un SharePoint Solution Package file (file WSP) di cui poi ne verrà fatto anche il &lt;b&gt;deploy&lt;/b&gt; sul server.用于SharePoint开发与Visual Studio 2010是很容易在事实上，，不仅可以开发一个像Visual Web部件项目客户端操作系统，使用Visual Studio 2010年，但这将创建一个SharePoint解决方案包文件（ wsp文件），当年也将在服务器上&lt;b&gt;部署&lt;/b&gt; 。 &lt;/p&gt;  &lt;p&gt;Oltre ad i template di progetto presenti in Visual Studio 2010 potete anche crearne di nuovi o estenderli grazie alla nuova &lt;b&gt;Visual Studio extensibility API&lt;/b&gt; , che vi permette di migliorarne il packaging, la validazione, il deployment, il tutto anche estendendo i nodi del Server Explorer.除了这些项目模板，您也可以创建新的或扩展&lt;b&gt;新&lt;/b&gt;的Visual Studio &lt;b&gt;可扩展API，&lt;/b&gt;它允许您以改善包装，验证，部署他们，所有节点同时扩展服务器资源管理器在Visual Studio 2010。 E&amp;#39; possibile ad esempio personalizzare il processo di build e deploy fatto da VS 2010 di feault aggiungento eventuali azioni custom e/o rimuovendo quelle di default. é&amp;#39;例如，可以自定义队2010年建造的制作过程，并部署到feault添加任何自定义操作和/或删除默认的。 &lt;/p&gt;  &lt;p&gt;Infatti potete accedere ai sites di SharePoint 2010 direttamente dal &lt;b&gt;Server Exporer&lt;/b&gt; e potrete guardare le impostazioni per siti, liste, content type, associazioni di workflow e altri oggetti.事实上，您可以从SharePoint &lt;b&gt;服务器&lt;/b&gt; 2010年&lt;b&gt;Exporer&lt;/b&gt;的网站，你可以直接监视网站，列表，内容类型，协会和其他工作流对象的设置。 Nella figura seguente potete farvi un&amp;#39;idea di come si naviga in SharePoint da Visual Studio.下图你可以得到一个如何在SharePoint导航与Visual Studio的想法。 &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/pietrobr/WindowsLiveWriter/SharePoint2010OverviewperDeveloper_A977/image_4.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="clip_image004" border="0" alt="clip_image004" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/5707.clip_5F00_image004_5F00_7F41900D.gif" width="278" height="312" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;b&gt;SharePoint Designer 2010&lt;/b&gt;&lt;b&gt; SharePoint&lt;/b&gt;&lt;b&gt;设计2010 &lt;/b&gt;&lt;/p&gt;  &lt;p&gt;Il nuovo SP Designer è lo strumento per lavorare con SP rivolto ai “Power User”- ma non solo direi- per reallizzare applicazioni con SP 2010.新的警司Designer是工作的工具与SP给“超级用户” -但不是说在2010年reallizzare与SP应用。 Una volta che la soluzione è stata realizzata questa può essere pacchettizzata in una SharePoint Solution (WSP) per poi essere importata e modificata con Visual Studio 2010.一旦该解决方案已经实施，可以封装在一个SharePoint解决方案（WSP）和进口，然后与Visual Studio 2010年修改。 &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/pietrobr/WindowsLiveWriter/SharePoint2010OverviewperDeveloper_A977/image_6.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="clip_image006" border="0" alt="clip_image006" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/7853.clip_5F00_image006_5F00_2585B870.gif" width="500" height="311" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Nella schermata seguente vedete SP Designer come si presenta: il menu di navigazione sulla sinistra dà accesso alle componenti che potete sviluppare dal Designer: libraries, workflows,在下一个屏幕上可以看到它是什么样子看起来警司设计师：在左侧的导航菜单中可以访问的组件，您可以通过设计开发：图书馆，工作流程， &lt;/p&gt;  &lt;p&gt;content types, data source, entities, site level settings etc.内容类型，数据源，实体，站点级别的设置等 &lt;/p&gt;  &lt;p&gt;&lt;b&gt;SharePoint Designer 2010: Workflow&lt;/b&gt; &lt;b&gt;SharePoint&lt;/b&gt;&lt;b&gt;设计2010年：工作流程&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;Con il nuovo SP Designer si potrà importare un workflow preparato, per non dire illustrato, da un&amp;#39; analista usando &lt;b&gt;Visio&lt;/b&gt; e si potrà poi dargli vita attraverso uno strumento visuale senza scrivere codice: azioni tipiche dei power users.随着新的警司设计师可以导入工作流程的准备，可以说，传单，一&amp;#39;分析师&lt;b&gt;使用&lt;/b&gt; Visio，您可以给它通过一个可视化工具，无需编写代码的生活：电力用户的典型行动。 Il nuovo Workflow potrà essere quindi esportato in un file WSP e successivamente importato in VS 2010.新的工作流，然后出口到wsp文件，并导入到2010年的队。 &lt;/p&gt;  &lt;p&gt;&lt;b&gt;SharePoint Designer 2010: Business Connectivity Services Design&lt;/b&gt; &lt;b&gt;SharePoint&lt;/b&gt;&lt;b&gt;设计2010年：商业连接服务设计&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;Il Business Connectivity Services sono l&amp;#39;eveoluzione del BDC, consentendo di esporre in SharePoint tramite le External List dati provienienti da sorgenti esterne allo SP.商业连接服务是eveoluzione该BDC，让您在SharePoint列表的数据显示，通过外部，从外部源头到SP来源。 Lo SP Designer 2010 semplifica la creazione delle entità che rapprenentano questi dati tramite un&amp;#160; wizard che guida verso la creazione di una connessione a servizi WCF, oggetti .NET, Database etc. 2010年的SP设计简化了实体创造，rapprenentano通过一个向导，这些数据对建立一个连接到WCF服务，指导他们的对象。NET中，数据库等。 &lt;/p&gt;  &lt;p&gt;&lt;b&gt;Developer Dashboard&lt;/b&gt;&lt;b&gt;开发仪表板 &lt;/b&gt;&lt;/p&gt;  &lt;p&gt;Nuovo utile strumento di debug, che ci consente di avere utili informazioni su quello che sta succedendo nella pagina: la developer dashboard colleziona informazioni statistiche relative al codice eseguito nella pagina ed eventuali eccezioni.新的有用的调试工具，它可以让我们对所发生的事情上页：仪表板的开发有关的统计资料收集的代码在页面上的任何异常运行有用的信息。 &lt;/p&gt;  &lt;p&gt;Può essere abilitata inizialmente così: 5月批准初步排定如下： &lt;/p&gt;  &lt;p&gt;&lt;i&gt;stsadm –o setproperty –pn developer-dashboard –pv OnDemand&lt;/i&gt; &lt;i&gt;通过Stsadm邻的setProperty -通知书开发商，仪表板，光伏按需&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;Può poi essere spenta e/o accessa dalla pagina dello SharePoint.然后可以关闭和/或从SharePoint访问。 &lt;/p&gt;  &lt;h5&gt;第2部分 &lt;/h5&gt;  &lt;p&gt;&lt;b&gt;Sandboxed solutions&lt;/b&gt;&lt;b&gt;沙箱解决方案 &lt;/b&gt;&lt;/p&gt;  &lt;p&gt;Una delle novità più interessanti della prossima release di SP 2010 sono le &lt;a href="http://203.208.37.132/translate_c?hl=zh-CN&amp;amp;sl=it&amp;amp;tl=zh-CN&amp;amp;u=http://msdn.microsoft.com/en-us/library/ee539083(office.14).aspx&amp;amp;rurl=translate.google.cn&amp;amp;usg=ALkJrhgliC5e32LG1nPRXL4CCNFb_Un8qQ"&gt;Sandboxed solution&lt;/a&gt; .其中一个最的SP二千○十顷&lt;a href="http://203.208.37.132/translate_c?hl=zh-CN&amp;amp;sl=it&amp;amp;tl=zh-CN&amp;amp;u=http://msdn.microsoft.com/en-us/library/ee539083(office.14).aspx&amp;amp;rurl=translate.google.cn&amp;amp;usg=ALkJrhgliC5e32LG1nPRXL4CCNFb_Un8qQ"&gt;沙箱解决方案&lt;/a&gt;的下一个版本有趣&lt;a href="http://203.208.37.132/translate_c?hl=zh-CN&amp;amp;sl=it&amp;amp;tl=zh-CN&amp;amp;u=http://msdn.microsoft.com/en-us/library/ee539083(office.14).aspx&amp;amp;rurl=translate.google.cn&amp;amp;usg=ALkJrhgliC5e32LG1nPRXL4CCNFb_Un8qQ"&gt;。&lt;/a&gt; Un nuovo modo di creare e deploiare soluzioni in Share Point 2010 con VS 2010 che può essere scelto durante la fase di deploy, come si vede dalla figura seguente:一种新的方法来创建和共享点deploiare在2010年在VS 2010解决方案可以在部署过程中选择，如下图所示： &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/pietrobr/WindowsLiveWriter/SharePoint2010overviewperDeveloperparte2_4D31/image_6.png"&gt;&lt;b&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="clip_image008" border="0" alt="clip_image008" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/1588.clip_5F00_image008_5F00_1DFCD9B4.gif" width="498" height="357" /&gt;&lt;/b&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Le Sendboxed solution offrono le seguenti caratteristiche:该解决方案Sendboxed提供以下功能： &lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;b&gt;facilità di deploy&lt;/b&gt; nella farm e su SharePoint OnLine, &lt;b&gt;sicurezza&lt;/b&gt; nel far girare le applicazioni che girando in una sandbox (=uno spazio a loro dedicato), offrendo maggior stabilità e basso rischio di compromettere l&amp;#39;intera farm. &lt;b&gt;易于部署&lt;/b&gt; ，在农场和SharePoint网络， &lt;b&gt;安全&lt;/b&gt;应用软件运行在沙箱中运行（=一个专门给他们空间），提供更稳定，危及整个农场的风险较低。 &lt;/li&gt;    &lt;li&gt;Lavorano con un insieme &lt;b&gt;ristretto di API SharePoint&lt;/b&gt; : Content Types, Site Columns, Custom Actions, Workflow dichiarativi,&amp;#160; Event Receivers, Feature Receivers, List Definitions, Site Pages, etc.工作与&lt;b&gt;共享点的API有限：&lt;/b&gt;内容类型，网站栏目，自定义操作，工作流声明，事件接收器，接收器功能，列表定义，网站网页等。       &lt;ul&gt;       &lt;li&gt;Un sottoinsieme di Microsoft.SharePoint. Microsoft.SharePoint一个子集。 Qui trovate la lista completa dei &lt;a href="http://203.208.37.132/translate_c?hl=zh-CN&amp;amp;sl=it&amp;amp;tl=zh-CN&amp;amp;u=http://msdn.microsoft.com/en-us/library/ee537860(office.14).aspx&amp;amp;rurl=translate.google.cn&amp;amp;usg=ALkJrhjaiFbYqA64DSICmmC0sXmdK7GSDg"&gt;tipi abilitati&lt;/a&gt; .下面是&lt;a href="http://203.208.37.132/translate_c?hl=zh-CN&amp;amp;sl=it&amp;amp;tl=zh-CN&amp;amp;u=http://msdn.microsoft.com/en-us/library/ee537860(office.14).aspx&amp;amp;rurl=translate.google.cn&amp;amp;usg=ALkJrhjaiFbYqA64DSICmmC0sXmdK7GSDg"&gt;通过类型&lt;/a&gt;的完整列表&lt;a href="http://203.208.37.132/translate_c?hl=zh-CN&amp;amp;sl=it&amp;amp;tl=zh-CN&amp;amp;u=http://msdn.microsoft.com/en-us/library/ee537860(office.14).aspx&amp;amp;rurl=translate.google.cn&amp;amp;usg=ALkJrhjaiFbYqA64DSICmmC0sXmdK7GSDg"&gt;。&lt;/a&gt;&lt;/li&gt;     &lt;/ul&gt;   &lt;/li&gt;    &lt;li&gt;Un meccanismo di Code Access Security (CAS) ne limita le funzionalità rispetto ad una soluition che gira in full-trust.一个代码访问安全（CA）的机制，限制功能相比soluition全面运行信任。 Le impostazioni sono le seguenti:在设置如下：      &lt;ul&gt;       &lt;li&gt;SharePointPermission.ObjectModel SharePointPermission.ObjectModel &lt;/li&gt;        &lt;li&gt;SecurityPermission.Execution SecurityPermission.Execution &lt;/li&gt;        &lt;li&gt;AspNetHostingPermissionLevel = Minimal AspNetHostingPermissionLevel =最小 &lt;/li&gt;     &lt;/ul&gt;   &lt;/li&gt;    &lt;li&gt;Vengono deploiate in una &lt;b&gt;Solution Gallery&lt;/b&gt; , che può essere gestita centralmente&amp;#160; e dal Central Admin è possibile stabilire quali risorse massime l&amp;#39;applicazione possa consumare.是deploiate &lt;b&gt;解决方案库，&lt;/b&gt;可管理，由中央管理的中央有可能确定哪些资源，应用程序可以消耗最大。       &lt;ul&gt;       &lt;li&gt;Le risorse possono essere diverse: CPU, Memoria, SQL etc e vengono misurate in &amp;#39;Resource Point&amp;#39;.资源可能是不同的：CPU，内存时，SQL等，并在&amp;#39;衡量资源点&amp;#39;。 &lt;/li&gt;     &lt;/ul&gt;   &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/pietrobr/WindowsLiveWriter/SharePoint2010overviewperDeveloperparte2_4D31/image_2.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="clip_image010" border="0" alt="clip_image010" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/2664.clip_5F00_image010_5F00_1AEA7BBF.gif" width="514" height="124" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;h5&gt;第3部分 &lt;/h5&gt;  &lt;p&gt;Le funzionalità di SharePoint 2010 raccolte in una slide. 2010年的SharePoint功能，在幻灯片中收集的。 &lt;/p&gt;  &lt;p&gt;Non tutte per soli developer, non vi preoccupate.不是只有开发商所有，请不要担心。 &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/pietrobr/WindowsLiveWriter/SharePoint2010overviewperdeveloperparte3_3DD6/image_2.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="clip_image012" border="0" alt="clip_image012" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/0820.clip_5F00_image012_5F00_6B2F63F0.gif" width="539" height="321" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Composites&lt;/b&gt; &lt;b&gt;复合材料&lt;/b&gt;&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Business Connectivity Services商业连接服务 &lt;/li&gt;    &lt;li&gt;InfoPath Form Services InfoPath窗体服务 &lt;/li&gt;    &lt;li&gt;External Links外部链接 &lt;/li&gt;    &lt;li&gt;Workflow工作流 &lt;/li&gt;    &lt;li&gt;SharePoint Designer SharePoint设计 &lt;/li&gt;    &lt;li&gt;Visual Studio视觉工作室 &lt;/li&gt;    &lt;li&gt;API Enhancements API改进 &lt;/li&gt;    &lt;li&gt;REST/ATOM/RSS的REST /的Atom / RSS &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&lt;b&gt;Sites&lt;/b&gt; &lt;b&gt;网站&lt;/b&gt;&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Ribbon UI功能区用户界面 &lt;/li&gt;    &lt;li&gt;SharePoint Workspace SharePoint工作区 &lt;/li&gt;    &lt;li&gt;SharePont Mobile SharePont手机 &lt;/li&gt;    &lt;li&gt;Office Client and Office Web Application办公室客户端和Office Web应用程序 &lt;/li&gt;    &lt;li&gt;Sandbox Support沙盒技术支持 &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&lt;b&gt;Communities&lt;/b&gt; &lt;b&gt;社区&lt;/b&gt;&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Tagging, Tag Cloud, Ratings标签，标签云，评级 &lt;/li&gt;    &lt;li&gt;Social bookmarking社会书签 &lt;/li&gt;    &lt;li&gt;Blogs and Wikis博客和wiki &lt;/li&gt;    &lt;li&gt;MySites MySites &lt;/li&gt;    &lt;li&gt;Activity Feeds活动订阅 &lt;/li&gt;    &lt;li&gt;Profiles and Expertise概况和专业知识 &lt;/li&gt;    &lt;li&gt;Org Browser牛津浏览器 &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&lt;b&gt;Content&lt;/b&gt; &lt;b&gt;内容&lt;/b&gt;&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Enterprice Content Types内容类型企业单位 &lt;/li&gt;    &lt;li&gt;Metadata and Navigation元数据和导航 &lt;/li&gt;    &lt;li&gt;Documents Sets文件集 &lt;/li&gt;    &lt;li&gt;Multi stage disposition多级配置 &lt;/li&gt;    &lt;li&gt;Audio and Video Content Types音频和视频内容类型 &lt;/li&gt;    &lt;li&gt;Remote Blob Storage远程一滴存储 &lt;/li&gt;    &lt;li&gt;List Enhancements名单增强 &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&lt;b&gt;Search&lt;/b&gt; &lt;b&gt;搜索&lt;/b&gt;&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Social Relevance社会意义 &lt;/li&gt;    &lt;li&gt;Phonetic Search语音搜索 &lt;/li&gt;    &lt;li&gt;Navigation导航 &lt;/li&gt;    &lt;li&gt;FAST Integration快速集成 &lt;/li&gt;    &lt;li&gt;Enhance Pipeline加强管道 &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&lt;b&gt;Insights&lt;/b&gt; &lt;b&gt;见解&lt;/b&gt;&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;PerformancePoint Services的PerformancePoint服务 &lt;/li&gt;    &lt;li&gt;Execel Services精通办公自动化服务 &lt;/li&gt;    &lt;li&gt;Chart Web Part图表Web部件 &lt;/li&gt;    &lt;li&gt;Visio Services Visio的服务 &lt;/li&gt;    &lt;li&gt;Web Analytics网络分析 &lt;/li&gt;    &lt;li&gt;SQL Server Integration SQL Server集成 &lt;/li&gt;    &lt;li&gt;PowerPivot PowerPivot &lt;/li&gt; &lt;/ul&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://community.icburner.com/aggbug.aspx?PostID=1989" width="1" height="1"&gt;</description><category domain="http://community.icburner.com/blogs/vs2010tests/archive/tags/VS2010/default.aspx">VS2010</category><category domain="http://community.icburner.com/blogs/vs2010tests/archive/tags/SharePoint/default.aspx">SharePoint</category></item><item><title>Visual Studio 2010 beta 2: a quick web tour</title><link>http://community.icburner.com/blogs/vs2010tests/archive/2009/10/26/visual-studio-2010-beta-2-a-quick-web-tour.aspx</link><pubDate>Mon, 26 Oct 2009 04:00:06 GMT</pubDate><guid isPermaLink="false">7695cfbe-8499-488a-81cc-9a443df3b4ce:1988</guid><dc:creator>革命</dc:creator><slash:comments>0</slash:comments><description>&lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Now that Visual Studio 2010 beta 2 has been released, you can have some fun exploring it, starting from the new splash screen :-)&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/pietrobr/WindowsLiveWriter/VisualStudio2010beta2aquickwebtour_13490/image_2.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="clip_image002" border="0" alt="clip_image002" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/3225.clip_5F00_image002_5F00_55B98345.gif" width="331" height="231" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;In this post I’m going to explore some of the news for web developer, not all but at least some:-)&lt;/p&gt;  &lt;p&gt;&lt;b&gt;A quick look at Silverlight 3.0 &lt;/b&gt;&lt;/p&gt;  &lt;p&gt;Silverlight 3.0 is now integrated in Visual Studio 2010 beta 2 : the developer runtime and the SDK are installed during the setup process.&lt;/p&gt;  &lt;p&gt;If you take a look to the project template you can see an options section with a combo-box for multi-targeting even for Silverlight. &lt;/p&gt;  &lt;p&gt;Multi-targeting is one of the main architectural changes of Visual Studio 2010: you can now use a single IDE for targeting different versions of&amp;#160; the full .NET and CLR. You can write code for .NET 2.0, 3.0 and&amp;#160; 3.5: they use the CLR version 2.0 and the new .NET Framework 4 that instead uses the new CLR 4.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/pietrobr/WindowsLiveWriter/VisualStudio2010beta2aquickwebtour_13490/image_4.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="clip_image004" border="0" alt="clip_image004" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/1172.clip_5F00_image004_5F00_68BA6457.gif" width="386" height="290" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Note: the RIA Services are not completely integrated with this build.&lt;/p&gt;  &lt;p&gt;With the beta 2, you can find an interactive editor for Silverlight , similar to the WPF. In the Following screen I’m using it to create some columns and rows and setting the columns size directly into the editor. &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/pietrobr/WindowsLiveWriter/VisualStudio2010beta2aquickwebtour_13490/image_6.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="clip_image006" border="0" alt="clip_image006" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/3666.clip_5F00_image006_5F00_7DF7CE25.gif" width="374" height="135" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;An you can now &lt;b&gt;double-click&lt;/b&gt; on the button in the preview pane to go to the click event hander to start writing code. &lt;/p&gt;  &lt;p&gt;Now that F# is a prime language for the .NET Framework 4 and Visual Studio 2010 you can even create a Silverlight Library in F# and start using functional programming, if you like it, even for Silverlight. The F# Silverlight Library is a project template in beta 2 that you can add to your solution.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/pietrobr/WindowsLiveWriter/VisualStudio2010beta2aquickwebtour_13490/image_8.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="clip_image008" border="0" alt="clip_image008" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/6864.clip_5F00_image008_5F00_19302727.gif" width="350" height="37" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;To use it with Silverlight&amp;#160; you can add a reference from the standard Silverlight project in Visual Studio 2010 to the F# library for Silverlight, I ‘ve tried to build some simple code in a F# module as show below; a simple example of calculus for the factorial using a recursive function.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/pietrobr/WindowsLiveWriter/VisualStudio2010beta2aquickwebtour_13490/image_10.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="clip_image010" border="0" alt="clip_image010" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/4621.clip_5F00_image010_5F00_49E85034.gif" width="482" height="103" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;And than you can call the MathModule as a static class from Silverlight code as usual C# or VB.NET code:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/pietrobr/WindowsLiveWriter/VisualStudio2010beta2aquickwebtour_13490/image_12.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="clip_image012" border="0" alt="clip_image012" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/4237.clip_5F00_image012_5F00_7FAA6903.gif" width="500" height="39" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;You could imagine a sophisticated computations.&lt;/p&gt;  &lt;p&gt;&lt;b&gt;A quick look at ASP.NET MVC 2&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;Visual Studio 2010 will be shipped with ASP.NET MVC 2 project template and you can start playing with it right now with the beta 2 bits. You can find all the stuffs that are already available with ASP.NET MVC 2 Preview 2 for Visual Studio 2008 as &lt;b&gt;Validation based on Metadata&lt;/b&gt;, &lt;b&gt;Client Side Validation &lt;/b&gt;and Single Project support for &lt;b&gt;Areas:&lt;/b&gt; an easy way to logically divide you project in independent parts.&lt;/p&gt;  &lt;p&gt;If you have already created a project with ASP.NET MVC 1.0 in Visual Studio 2008 you can’t open it in Visual Studio 2010 beta 2 and you have to migrate it manually or using &lt;a href="http://weblogs.asp.net/leftslipper/archive/2009/10/19/migrating-asp-net-mvc-1-0-applications-to-asp-net-mvc-2.aspx"&gt;this tool&lt;/a&gt;. If you have instead created a project with ASP.NET MVC 2 Preview 2, you should reasonably succeed to migrate it to Visual Studio 2010 beta 2. I’ve opened one of my project built on ASP.NET MVC 2 Preview 2 and the Visual Studio 2010’s wizard have done the hard work for me. A message box asked me if I wanted to update the project to .NET Framework 4, as show below:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/pietrobr/WindowsLiveWriter/VisualStudio2010beta2aquickwebtour_13490/image_18.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="clip_image014" border="0" alt="clip_image014" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/1184.clip_5F00_image014_5F00_065D7287.gif" width="496" height="163" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;At the end the solution works fine, at least on “My Machine” :-).&lt;/p&gt;  &lt;p&gt;If you run the web app with the ASP.NET Developer Server you can see now that it’s running with the version 4 of the .NET Framework, as you can see below:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/pietrobr/WindowsLiveWriter/VisualStudio2010beta2aquickwebtour_13490/image_20.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="clip_image016" border="0" alt="clip_image016" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/5710.clip_5F00_image016_5F00_1CB317CC.gif" width="372" height="215" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Thanks to the new syntax of ASP.NET 4 you can even write code without the need of using HTML.Encode, using the syntax below:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/pietrobr/WindowsLiveWriter/VisualStudio2010beta2aquickwebtour_13490/image_14.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="clip_image018" border="0" alt="clip_image018" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/6303.clip_5F00_image018_5F00_3374F006.gif" width="246" height="91" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Instead of the more verbose:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/pietrobr/WindowsLiveWriter/VisualStudio2010beta2aquickwebtour_13490/image_16.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="clip_image020" border="0" alt="clip_image020" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/2677.clip_5F00_image020_5F00_3A27F989.gif" width="276" height="64" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Ok, some syntactic sugar, but of course if you write it hundreds of times… &lt;/p&gt;  &lt;p&gt;For more details you can read the &lt;a href="http://haacked.com/archive/2009/10/20/vs10beta2-and-aspnetmvc.aspx"&gt;Phil Haack post : VS10 Beta 2 From an ASP.NET MVC Perspective&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;&lt;b&gt;A quick look at ASP.NET 4 Web Forms&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;You have now the chance&amp;#160; to create a project structurally similar to ASP.NET MVC one: I mean with CSS, a Home and About pages. If you create a ASP.NET Web Application project and you press F5, for example, you’ll see the following screen:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/pietrobr/WindowsLiveWriter/VisualStudio2010beta2aquickwebtour_13490/image_22.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="clip_image022" border="0" alt="clip_image022" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/1172.clip_5F00_image022_5F00_59D6D351.gif" width="498" height="328" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;In the project you can even find jQuery 1.3.2 in the Scripts folder.&lt;/p&gt;  &lt;p&gt;If you came from Visual Studio 2008 and you prefer to have a blank solution, you have to choose&amp;#160; the Empty Project Template.&lt;/p&gt;  &lt;p&gt;One of the most evident new feature of ASP.NET 4 (both Web Forms and MVC), already present from beta 1, is that you can have different config files for debug and release and other configurations. For example you already have a Web.Debug.config and Web.Release.config for the two different configuration.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/pietrobr/WindowsLiveWriter/VisualStudio2010beta2aquickwebtour_13490/image_24.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="clip_image024" border="0" alt="clip_image024" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/3731.clip_5F00_image024_5F00_702C7896.gif" width="182" height="68" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;For example you can use the two files to set different connection strings for debugging and production.&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Code Snippets&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;You can now find some pre-build code snippets that works in the aspx editor, for example you can choose formview snippet as show below&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/pietrobr/WindowsLiveWriter/VisualStudio2010beta2aquickwebtour_13490/image_26.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="clip_image026" border="0" alt="clip_image026" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/7457.clip_5F00_image026_5F00_52BA278A.gif" width="460" height="259" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;And the editor generate some code for you:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/pietrobr/WindowsLiveWriter/VisualStudio2010beta2aquickwebtour_13490/image_28.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="clip_image028" border="0" alt="clip_image028" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/2577.clip_5F00_image028_5F00_3B8EAD0C.gif" width="344" height="88" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;This make more productive writing code directly into the editor, skipping the boring stuff.&lt;/p&gt;  &lt;p&gt;&lt;b&gt;ASP.NET 4 WebForms Routing&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;ASP.NET 4 WebForms can now use routing rules as much as ASP.NET MVC does. You can now use urls that are SEO friendly and human readable, for example&lt;/p&gt;  &lt;p&gt;&lt;i&gt;localhost/blog/archive/1&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;instead of&lt;/p&gt;  &lt;p&gt;&lt;i&gt;localhost/blog/default.aspx?Id=1&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;Just adding some code on the global.asax to define the rules:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/pietrobr/WindowsLiveWriter/VisualStudio2010beta2aquickwebtour_13490/image_30.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="clip_image030" border="0" alt="clip_image030" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/2158.clip_5F00_image030_5F00_34033D9F.gif" width="476" height="189" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;You can then retrieve data used in the rules and using it in code-behind or even create a new url using the same rules. I suggest you reading the ScottGu’s post on this &lt;a href="http://weblogs.asp.net/scottgu/archive/2009/10/13/url-routing-with-asp-net-4-web-forms-vs-2010-and-net-4-0-series.aspx"&gt;topic here&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;&lt;b&gt;ClientIDMode and ViewStateMode&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;If in the past you have had some problem with client id generated by Web Forms , “ctrl_” nested especially when you use master-page… now you have some good news, because you can set the behavior on a control:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/pietrobr/WindowsLiveWriter/VisualStudio2010beta2aquickwebtour_13490/image_32.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="clip_image032" border="0" alt="clip_image032" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/8424.clip_5F00_image032_5F00_642D1913.gif" width="249" height="127" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;You can inherit from the parent, make it predictable so that it can be easily used with CSS and Javascript or just static. &lt;/p&gt;  &lt;p&gt;And you can turn off view&amp;#160; state for a page and enable for a control using the control property ViewStateMode.&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Download&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;To fully explore Visual Studio 2010 beta 2 I strongly encourage you to &lt;a href="http://msdn.microsoft.com/it-it/evalcenter/dd819107(en-us).aspx"&gt;download from here&lt;/a&gt;.(from 21/10). MSDN Subscriber can download just from today.&lt;/p&gt;  &lt;p&gt;You can read the official announcement from &lt;a href="http://blogs.msdn.com/somasegar/archive/2009/10/19/announcing-visual-studio-2010-and-net-fx-4-beta-2.aspx"&gt;here&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;Per gli italiani che leggono questo post, ci saranno diverse occasioni durante l’anno per parlare delle novità di Visual Studio 2010, una fra tutte sono i &lt;a href="http://techdays-wpc.it/"&gt;Microsoft TechDays WPC 2009&lt;/a&gt;.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://community.icburner.com/aggbug.aspx?PostID=1988" width="1" height="1"&gt;</description><category domain="http://community.icburner.com/blogs/vs2010tests/archive/tags/VS2010/default.aspx">VS2010</category><category domain="http://community.icburner.com/blogs/vs2010tests/archive/tags/Beta+2/default.aspx">Beta 2</category></item><item><title>Web Platform Installer 2.0</title><link>http://community.icburner.com/blogs/vs2010tests/archive/2009/10/26/web-platform-installer-2-0.aspx</link><pubDate>Mon, 26 Oct 2009 03:43:01 GMT</pubDate><guid isPermaLink="false">7695cfbe-8499-488a-81cc-9a443df3b4ce:1987</guid><dc:creator>革命</dc:creator><slash:comments>0</slash:comments><description>&lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;h3&gt;Overview &lt;/h3&gt;  &lt;p&gt;Now that the Web Platform Installer 2.0 is RTW, WebPI for short, I’ll have some fun exploring some installation options with a series of posts. &lt;/p&gt;  &lt;p&gt;The Web PI is the easiest an quickest way to install software on Windows to run web applications. You can use it to run ASP, ASP.NET and PHP applications. If you are a developer that works both in ASP.NET and PHP or you need to run multiple apps running different runtimes, I think that it’ll be a useful tool and even for free! You can install IIS and related extensions, SQL Server 2008 Express, Visual Web Developer 2008 and others free tools or trial for web developers.&lt;/p&gt;  &lt;p&gt;After you install the Web PI you can use it even to update your current installation. The Web PI allows you to install beta/RC and RTM components. If you run it when a new release is available you can install the latest ones.&lt;/p&gt;  &lt;p&gt;Web PI is now available in 9 different languages.&lt;/p&gt;  &lt;p&gt;From the Web Platform Installer 2.0 you have access to Web Gallery, where you can download and run the most popular open source apps, both for ASP.NET and PHP. If you choose one of that app you have a straightforward installation experience directly inside the Web PI.&lt;/p&gt;  &lt;p&gt;The Web PI run on Windows Vista, Windows Vista SP1, Windows XP SP2+, Windows Server 2003 SP1+, Windows Server 2008 and Windows 7.&lt;/p&gt;  &lt;p&gt;You can &lt;a href="http://www.microsoft.com/web/Downloads/platform.aspx"&gt;download the Web PI from here&lt;/a&gt;, from &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=D87A71E4-00BD-4204-8F25-F245FEB0C3AD&amp;amp;displaylang=en"&gt;this link you can easily choose you language&lt;/a&gt;. &lt;/p&gt;  &lt;p&gt;&lt;b&gt;Running Web Platform Installer from Windows XP&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;If you run it from Windows XP (I’m running an instance of WinXp from my Windows 7 machine using the XPMode feature), you’ll see something similar:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/pietrobr/WindowsLiveWriter/WebPlatformInstaller2.0_9311/image_4.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="clip_image002" border="0" alt="clip_image002" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/2642.clip_5F00_image002_5F00_595FF14A.gif" width="485" height="361" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;As you can see it’s easy to understand, there are three tabs:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;b&gt;What’s News ?&lt;/b&gt; : for the latest components available and new apps from the Gallery: you can see Moodle, SugarCRM, Sitefinity Community Editions etc. &lt;/li&gt;    &lt;li&gt;&lt;b&gt;Web Platform&lt;/b&gt;: all the settings related to the configuration of IIS &lt;/li&gt;    &lt;li&gt;&lt;b&gt;Web Applications&lt;/b&gt;:&amp;#160; apps from the Gallery sort by categories &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;If you look at the left-bottoms corner you can click the Options link that opens up a new dialog where you can see more options:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/pietrobr/WindowsLiveWriter/WebPlatformInstaller2.0_9311/image_6.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="clip_image004" border="0" alt="clip_image004" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/5314.clip_5F00_image004_5F00_4A0BCD94.gif" width="457" height="316" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;You can see two check buttons for more tabs for IIS Media Features and Developers tools. Because I’m running on Windows XP, no real Media Extensions are available and I only see the Developer Tools tab. At the end you can notice the preferred language you can use for software installation. At the end you can delete the installer cache. Flagging the Developer tools you can see a new tab on the menu:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/pietrobr/WindowsLiveWriter/WebPlatformInstaller2.0_9311/image_10.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="clip_image006" border="0" alt="clip_image006" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/6765.clip_5F00_image006_5F00_44BCE6E3.gif" width="466" height="350" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Now you can click on the link “Click to include the recommended products”, or “Customize” to see the products suggested and start the installation.&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Running Web Platform Installer from Windows 7&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;I’m running it from Windows 7 now, and of course I can see more options, that we’ll see in more details in a different post. &lt;/p&gt;  &lt;p&gt;After I flag the two check boxes in the options window (see the image upward for the XP) I can even see a new tab for Media stuffs: where, for example, you can install the necessary components for delivering on-demand and live contents via Media Services.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/pietrobr/WindowsLiveWriter/WebPlatformInstaller2.0_9311/image_12.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="clip_image008" border="0" alt="clip_image008" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/2161.clip_5F00_image008_5F00_01E0A269.gif" width="473" height="351" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;As you see from this post the Web PI is easy to use, in the following post we’ll explore some settings in the Web Platform tab in my Windows XP machine and Windows 7.&lt;/p&gt;  &lt;h3&gt;Web Platform for Windows XP &lt;/h3&gt;  &lt;p&gt;For an overview of the Web PI 2.0 you can read my previous post of &lt;a href="http://blogs.msdn.com/pietrobr/archive/2009/10/01/web-platform-installer-2-0-overview.aspx"&gt;these series here&lt;/a&gt;, before you proceed reading.&lt;/p&gt;  &lt;p&gt;In this post I’ll dig into the options available for Windows XP users in the “Web Platform” tab, as show below (as they show on my machine):&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/pietrobr/WindowsLiveWriter/WebPlatformInst.0WebPlatformforWindowsXP_918F/image_26.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="clip_image010" border="0" alt="clip_image010" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/0508.clip_5F00_image010_5F00_41AD199F.gif" width="486" height="428" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Here you can see these sections: &lt;b&gt;Web Server, Framework and Runtimes, Database and Tools&lt;/b&gt;. If I click customize you see the products/components you can install. If you expand clicking on customize you see the details, with a little info icon. If you click the little info icon you’ll see more info on the component to install.&lt;/p&gt;  &lt;p&gt;In the following section you’ll see more info trying to install some software on my Windows XP virtual machine.&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Installing components from Web Server&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;For example if you click in the Internet information services 5.1&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/pietrobr/WindowsLiveWriter/WebPlatformInst.0WebPlatformforWindowsXP_918F/image_2.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="clip_image012" border="0" alt="clip_image012" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/4621.clip_5F00_image012_5F00_733B17E5.gif" width="240" height="50" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;You’ll see the description for IIS 5.1:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/pietrobr/WindowsLiveWriter/WebPlatformInst.0WebPlatformforWindowsXP_918F/image_4.png"&gt;alt=image title=image border=0 v:shapes=&amp;quot;_x0000_i1037&amp;quot;&amp;gt; &lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Here you have the options to install some products, the most interesting ones for me are:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;IIS 5.1 : of course for running my web apps &lt;/li&gt;    &lt;li&gt;&lt;b&gt;FastCGI&amp;#160; 1.0&lt;/b&gt; for IIS 5.1 : is an extension for IIS that you can use for running PHP application in both reliable and fastest way. I strongly recommend this if you plan to run PHP applications on Windows.&amp;#160; &lt;/li&gt;    &lt;li&gt;&lt;b&gt;Web Deployment tool&lt;/b&gt;: this is a free tool that can be used for different purposes, the nicest features is that it can be used to package a site with all related contents : database, ACL, GAC, COM objects, Registry settings to be easily used for deploy on another machine or to migrate sites/web applications from IIS 6.0 to IIS 7.0 &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;You can now select your preferred:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/pietrobr/WindowsLiveWriter/WebPlatformInst.0WebPlatformforWindowsXP_918F/image_6.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="clip_image016" border="0" alt="clip_image016" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/6283.clip_5F00_image016_5F00_47F680DE.gif" width="437" height="320" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Then click the install button…&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/pietrobr/WindowsLiveWriter/WebPlatformInst.0WebPlatformforWindowsXP_918F/image_8.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="clip_image018" border="0" alt="clip_image018" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/7357.clip_5F00_image018_5F00_228C8D70.gif" width="434" height="292" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Now you can see that the WebPI add &lt;b&gt;some dependencies for me.&lt;/b&gt; I’ll install the Web Deployment Tool 1.0, Italian version because I’ve selected the Italian language in the options link, see my previous post, and the Web PI added two dependencies : SQL Server 2008 Management Objects and SQL Server Native Client, nice !!&lt;/p&gt;  &lt;p&gt;If “I Accept”, the setup starts:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/pietrobr/WindowsLiveWriter/WebPlatformInst.0WebPlatformforWindowsXP_918F/image_10.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="clip_image020" border="0" alt="clip_image020" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/8424.clip_5F00_image020_5F00_5BA5FB23.gif" width="407" height="284" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;And all works on my machine :-), and I can see the final screen:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/pietrobr/WindowsLiveWriter/WebPlatformInst.0WebPlatformforWindowsXP_918F/image_12.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="clip_image022" border="0" alt="clip_image022" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/2577.clip_5F00_image022_5F00_005C33FD.gif" width="410" height="283" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;etc voila, we’re done.&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Installing components from Framework and Runtimes&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;In this section you can install &lt;b&gt;.NET Framework 3.5 SP1&lt;/b&gt;, that is already installed on my machine and that you need if you’d like to run ASP.NET Web Forms applications. You can also install the &lt;b&gt;ASP.NET MVC 1.0 framework&lt;/b&gt;, now you can use the Model-View-Controller pattern with ASP.NET core features. And you can install the&lt;b&gt; PHP&lt;/b&gt; runtime 5.2.11; so you could run both ASP.NET and PHP apps on Windows Web Platform. OK I don’t suggest you using XP on production servers, but for developer purposes it could be done.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/pietrobr/WindowsLiveWriter/WebPlatformInst.0WebPlatformforWindowsXP_918F/image_14.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="clip_image024" border="0" alt="clip_image024" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/2161.clip_5F00_image024_5F00_56E7F2BC.gif" width="515" height="382" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;You have the review screen, again, and you’re ready to install.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/pietrobr/WindowsLiveWriter/WebPlatformInst.0WebPlatformforWindowsXP_918F/image_16.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="clip_image026" border="0" alt="clip_image026" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/4705.clip_5F00_image026_5F00_62140DB7.gif" width="512" height="355" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Installing components from Database&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;From here you have the options to install SQL Server 2008 Express ( that it’ free)&amp;#160; and related stuffs, for example the Management Studio: the console used to administer SQL Server 2008.&lt;/p&gt;  &lt;p&gt;You can see the screenshot on my machine: &lt;b&gt;SQL Server 2008 Express with Service Pack 1&lt;/b&gt; and the Managements Objects are already installed.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/pietrobr/WindowsLiveWriter/WebPlatformInst.0WebPlatformforWindowsXP_918F/image_18.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="clip_image028" border="0" alt="clip_image028" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/1172.clip_5F00_image028_5F00_77FD8007.gif" width="507" height="378" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;In the review screen I can see that the Web PI installs even &lt;b&gt;Windows PowerShell&lt;/b&gt; as a &lt;b&gt;dependency&lt;/b&gt; from the Management Studio Express:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/pietrobr/WindowsLiveWriter/WebPlatformInst.0WebPlatformforWindowsXP_918F/image_20.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="clip_image030" border="0" alt="clip_image030" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/5381.clip_5F00_image030_5F00_435FB47D.gif" width="506" height="273" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Installing Tools&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;In the tools section you can download &lt;b&gt;Visual Web Developer 2008 Express with SP1&lt;/b&gt;, a free tool, and the &lt;b&gt;Silverlight 3 tool for Visual Studio&lt;/b&gt;, even this tool is for free.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/pietrobr/WindowsLiveWriter/WebPlatformInst.0WebPlatformforWindowsXP_918F/image_24.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="clip_image032" border="0" alt="clip_image032" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/6378.clip_5F00_image032_5F00_32E74382.gif" width="504" height="208" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Ok now you’re ready for building and running&amp;#160; web apps. We’ll see in a later post how to install one app from the Gallery.&lt;/p&gt;  &lt;p&gt;&lt;b&gt;&lt;/b&gt;&lt;/p&gt;  &lt;h3&gt;Web Platform for Windows 7 &lt;/h3&gt;  &lt;p&gt;Now I’ll use the Web PI on my Windows 7 machine and I’ll show the options available.&lt;/p&gt;  &lt;p&gt;You can start from main screen and select the “Web Platform” tab:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/pietrobr/WindowsLiveWriter/WebPlatformInsta.0WebPlatformforWindows7_1429D/image52.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="clip_image034" border="0" alt="clip_image034" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/8037.clip_5F00_image034_5F00_6957F584.gif" width="458" height="417" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Here you can see these sections: &lt;b&gt;Web Server, Framework and Runtimes, Database and Tools&lt;/b&gt;. If I click customize you see products/components you can install. If you expand clicking on customize you see the details, with a little info icon. If you click the little info icon you’ll see more info on the component to install.&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Installing components from Web Server&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;If you look into the options for IIS 7.x web Server you can see a lot of functionalities that you can install. I’ve already installed&lt;b&gt; ASP.NET module&lt;/b&gt; that I use for ASP.NET apps, the &lt;b&gt;CGI&lt;/b&gt; that install the FastCGI module and that I use for PHP apps. IIS 7 is a modular web server and you can decide which module to install based on your needed. One of my preferred module is the &lt;b&gt;URL Rewriter&lt;/b&gt;, version 1.1. You can use to build rules to implement nice URL&amp;#160; for users and for Search Engine Optimization (SEO). You can use Regular expression, pattern matching, Wildcard pattern matching or rewrite maps.&lt;/p&gt;  &lt;p&gt;You can see a ton of features available for IIS 7.5:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/pietrobr/WindowsLiveWriter/WebPlatformInsta.0WebPlatformforWindows7_1429D/image_2.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="clip_image036" border="0" alt="clip_image036" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/7853.clip_5F00_image036_5F00_2AF4C282.gif" width="402" height="933" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Now I can proceed with the installation, before I need to check the software I decide to install and &lt;b&gt;related dependencies&lt;/b&gt;.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/pietrobr/WindowsLiveWriter/WebPlatformInsta.0WebPlatformforWindows7_1429D/image_6.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="clip_image038" border="0" alt="clip_image038" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/0412.clip_5F00_image038_5F00_60F9418F.gif" width="493" height="489" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;One of the component I’d like to install is the &lt;b&gt;URL Rewriter 2.0 Beta&lt;/b&gt;, that it’s very attractive because it supports outbound rules: that can fix links on the fly in a response from the server.&amp;#160;&amp;#160; Because is a Beta I don’t see in this section, so I go to the “What’s new Tab” and I can see the “&lt;b&gt;Beta Extensions&lt;/b&gt;” where I can found the &lt;b&gt;URL Rewriter 2.0 Beta&lt;/b&gt;.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/pietrobr/WindowsLiveWriter/WebPlatformInsta.0WebPlatformforWindows7_1429D/image_8.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="clip_image040" border="0" alt="clip_image040" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/0820.clip_5F00_image040_5F00_4DDAA594.gif" width="484" height="286" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Because the &lt;b&gt;URL Rewriter 1.1&lt;/b&gt; and the &lt;b&gt;URL Rewriter 2.0 beta&lt;/b&gt; can’t run on the same machine, if I select the check box I receive a warning message.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/pietrobr/WindowsLiveWriter/WebPlatformInsta.0WebPlatformforWindows7_1429D/image_12.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="clip_image042" border="0" alt="clip_image042" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/6378.clip_5F00_image042_5F00_1D4727DC.gif" width="369" height="154" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;So I need to uninstall version 1.1 from Control Panel and install the version 2.0 beta from Web PI. &lt;/p&gt;  &lt;p&gt;&lt;b&gt;Installing components from Database&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;In this section you can find the same components you can find for Windows XP, plus the &lt;b&gt;SQL Server driver 1.0 for PHP, &lt;/b&gt;a native extension for PHP apps,&lt;b&gt; &lt;/b&gt;that you can install on Windows 7, as see below:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/pietrobr/WindowsLiveWriter/WebPlatformInsta.0WebPlatformforWindows7_1429D/image_14.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="clip_image044" border="0" alt="clip_image044" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/1007.clip_5F00_image044_5F00_589A8D9A.gif" width="529" height="394" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Installing components from Framework and Runtimes, Tools&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;These two sections are basically the same as we saw on Window XP, and you can refer two the previous blog for details.&lt;/p&gt;  &lt;p&gt;Next step, installing some application from the galley … stay tuned.&lt;/p&gt;  &lt;p&gt;&lt;b&gt;&lt;/b&gt;&lt;/p&gt;  &lt;h3&gt;Installing PHP Apps &lt;/h3&gt;  &lt;p&gt;In this post I’m going to explore the most important feature for the version 2.0 of the WebPI: now you can install the most popular Open Source applications for both ASP.NET and PHP directly from the installer.&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Installing WordPress (PHP)&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;You can use the Web Applications’ tab to choose your preferred ones, you can navigate by category or by name, for example. In the following pictures I’ve select WordPress:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/pietrobr/WindowsLiveWriter/WebPlatformInstaller2.0InstallingApps_EC98/image_2.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="clip_image046" border="0" alt="clip_image046" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/8015.clip_5F00_image046_5F00_1147C859.gif" width="449" height="335" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;You can now press install and you’ll be redirected to a summary page where the installer show all dependencies needed to run WordPress. Because I haven’t installed MySQL, the Web PI 2.0 will install it for me and even other components as the URL Rewrite module. I really love this feature!! The following is an image of that one:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/pietrobr/WindowsLiveWriter/WebPlatformInstaller2.0InstallingApps_EC98/image_4.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="clip_image048" border="0" alt="clip_image048" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/6787.clip_5F00_image048_5F00_50A80C9A.gif" width="459" height="319" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;I’m guided, inside the installer, to the process of installing the software.&lt;/p&gt;  &lt;p&gt;First I need to set the password for MySQL’s root account as show below: &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/pietrobr/WindowsLiveWriter/WebPlatformInstaller2.0InstallingApps_EC98/image_6.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="clip_image050" border="0" alt="clip_image050" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/6874.clip_5F00_image050_5F00_311DDE27.gif" width="462" height="320" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Than I need to enter some site information, so, for example, Web Site name in step 1, as show below:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/pietrobr/WindowsLiveWriter/WebPlatformInstaller2.0InstallingApps_EC98/image_8.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="clip_image052" border="0" alt="clip_image052" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/6283.clip_5F00_image052_5F00_39A13D71.gif" width="470" height="326" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;And some information for creating and configuring the database:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/pietrobr/WindowsLiveWriter/WebPlatformInstaller2.0InstallingApps_EC98/image_10.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="clip_image054" border="0" alt="clip_image054" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/2148.clip_5F00_image054_5F00_5A4D2878.gif" width="472" height="329" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;And at the end of installation you can run your application from the Launch Link and you have the first screenshot of WordPress installation page: &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/pietrobr/WindowsLiveWriter/WebPlatformInstaller2.0InstallingApps_EC98/image_12.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="clip_image056" border="0" alt="clip_image056" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/8831.clip_5F00_image056_5F00_7755D740.gif" width="462" height="409" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;As you have briefly seen you could easily use the Web PI both for installing and configuring your environment and for installing your preferred apps in some simple steps. &lt;/p&gt;  &lt;p&gt;&lt;b&gt;&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;&lt;b&gt;&lt;/b&gt;&lt;/p&gt;  &lt;h3&gt;Installing ASP.NET Apps&lt;/h3&gt;  &lt;p&gt;In this post we’ll the Web PI 2.0 to install &lt;b&gt;BlogEngine.NET&lt;/b&gt;, one of the most popular Open Source applications for ASP.NET.&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Installing BlogEngine.NET (ASP.NET)&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;You can use the Web Applications’ tab to choose your preferred one, you can navigate by category or by name, for example. In the following pictures I’ve select BlogEngine.Net:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/pietrobr/WindowsLiveWriter/WebPlatformInstaller2.0Installin.NETApps_F5BF/image_2.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="clip_image058" border="0" alt="clip_image058" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/4621.clip_5F00_image058_5F00_4D339445.gif" width="508" height="378" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;You can now press install and you’ll be redirected to a summary page where the installer show all dependencies needed to run BlogEngine.NET, a few on my machine, as shown in the following image:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/pietrobr/WindowsLiveWriter/WebPlatformInstaller2.0Installin.NETApps_F5BF/image_4.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="clip_image060" border="0" alt="clip_image060" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/8030.clip_5F00_image060_5F00_0459CFE7.gif" width="500" height="347" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;I’m guided, inside the installer, to the process of installing the software, I need to enter site information, so for example Web Site name and others, as show below:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/pietrobr/WindowsLiveWriter/WebPlatformInstaller2.0Installin.NETApps_F5BF/image_6.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="clip_image062" border="0" alt="clip_image062" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/4718.clip_5F00_image062_5F00_51F88D18.gif" width="500" height="347" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;And at the end of installation you can run your application from the Launch Link and you have the first screenshot of BlogEngine.NET installation page:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/pietrobr/WindowsLiveWriter/WebPlatformInstaller2.0Installin.NETApps_F5BF/image_8.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="clip_image064" border="0" alt="clip_image064" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/7457.clip_5F00_image064_5F00_5A0FB96D.gif" width="507" height="400" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;And we’re done! &lt;/p&gt;  &lt;p&gt;As you so you could easily use the Web PI both for installing and configuring your environment and for installing your preferred apps in some simple steps. &lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://community.icburner.com/aggbug.aspx?PostID=1987" width="1" height="1"&gt;</description><category domain="http://community.icburner.com/blogs/vs2010tests/archive/tags/Web+Platform+Installer+2.0/default.aspx">Web Platform Installer 2.0</category></item><item><title>ASP.NET MVC 2 Preview 2: Client-Side Validation</title><link>http://community.icburner.com/blogs/vs2010tests/archive/2009/10/26/asp-net-mvc-2-preview-2-client-side-validation.aspx</link><pubDate>Mon, 26 Oct 2009 02:56:53 GMT</pubDate><guid isPermaLink="false">7695cfbe-8499-488a-81cc-9a443df3b4ce:1986</guid><dc:creator>革命</dc:creator><slash:comments>0</slash:comments><description>&lt;p&gt;ASP.NET MVC 2 Preview 2: Client-Side Validation&lt;/p&gt;  &lt;p&gt;In my opinion one of the most interesting features of ASP.NET MVC 2.0 Preview 2 is the support for client-side validation.&lt;/p&gt;  &lt;p&gt;How-to enable Client-Side validation&lt;/p&gt;  &lt;p&gt;Client-side validation enable your application to perform client-side validation based on model’s validation by JQuery validation library. Ok, it’s simpler than it sounds.&lt;/p&gt;  &lt;p&gt;The client-side validation framework is even extensible, but for now it suits my simple needs.&lt;/p&gt;  &lt;p&gt;In &lt;a href="http://blogs.msdn.com/pietrobr/archive/2009/07/31/il-nuovo-asp-net-mvc-2-preview-1.aspx"&gt;my post on ASP.NET MVC 2.0 Preview 1&lt;/a&gt; I’ve added &lt;i&gt;server-side&lt;/i&gt; validation to my application model using metadata as ASP.NET Dynamic Data does. So, for example, in the the picture below I’ve added a partial class to my model and a class for metadata describing my requirements for validation. In the following code the attribute ‘Titolo’ must be not null, and I’ve added an Error Message if something’s wrong.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/pietrobr/WindowsLiveWriter/ASP.NETMVC2Preview2ClientValidation_F1A7/image_2.png"&gt;&lt;img style="border-right-width:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;" title="clip_image002" border="0" alt="clip_image002" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/4705.clip_5F00_image002_5F00_59DCC79E.gif" width="459" height="197" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;If I run the application all works fine: I show a view page to the user, user enters some value and press Save to submit to server. If the user doesn’t fill the title field he gets an error as soon as we made a POST to server. You can see the page flickering in the browser.&lt;/p&gt;  &lt;p&gt;Client-side validation prevent your app going to the server for validation and all happens client side, but using the rules you have defined on the partial class you saw before.&lt;/p&gt;  &lt;p&gt;To enable client side validation, you can follow these easy steps:&lt;/p&gt;  &lt;p&gt;· use &lt;b&gt;Html.EnableClientValidation&lt;/b&gt; method on the View file &lt;/p&gt;  &lt;p&gt;· insert three javascript files : &lt;b&gt;jquery-1.3.2.js&lt;/b&gt;, &lt;b&gt;jquery.validate.js&lt;/b&gt;, &lt;b&gt;MicrosoftMvcJQueryValidation.js&lt;/b&gt;. These files are included in the Scripts directory coming with ASP.NET MVC 2 Preview 2 project template.&amp;#160; &lt;/p&gt;  &lt;p&gt;I’ve put the code in my view page for editing some simple fields.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/pietrobr/WindowsLiveWriter/ASP.NETMVC2Preview2ClientValidation_F1A7/image_4.png"&gt;&lt;img style="border-right-width:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;" title="clip_image004" border="0" alt="clip_image004" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/5381.clip_5F00_image004_5F00_292B8EFD.gif" width="656" height="222" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Now I can run my application and see the results, I’m using HttpWatch to see that no requests are performed to the server and the validation logic works as expected.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/pietrobr/WindowsLiveWriter/ASP.NETMVC2Preview2ClientValidation_F1A7/image_6.png"&gt;&lt;img style="border-right-width:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;" title="clip_image006" border="0" alt="clip_image006" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/8015.clip_5F00_image006_5F00_1200147F.gif" width="484" height="583" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;As soon as I type something into the textbox the red message disappears. &lt;/p&gt;  &lt;p&gt;Nice feature! You can download the ASP.NET MVC 2 Preview 2 &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=d3f06bb9-5f5f-4f46-91e9-813b3fce2db1&amp;amp;displaylang=en"&gt;from here&lt;/a&gt; and read about all the features on &lt;a href="http://haacked.com/archive/2009/10/01/asp.net-mvc-preview-2-released.aspx"&gt;Phil Haack post&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;   &lt;p&gt;&amp;#160;&lt;/p&gt;    &lt;p&gt;&lt;b&gt;新的ASP.NET MVC 2 -预览1 &lt;/b&gt;&lt;b&gt;&lt;a href="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/2642.clip_5F00_image001_5F00_751ED392.gif"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="clip_image001" border="0" alt="clip_image001" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/2664.clip_5F00_image001_5F00_thumb_5F00_19B2F1C8.gif" width="6" height="12" /&gt;&lt;/a&gt;&lt;a href="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/3644.clip_5F00_image003_5F00_64A66297.gif"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="clip_image003" border="0" alt="clip_image003" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/5707.clip_5F00_image003_5F00_thumb_5F00_4734118B.gif" width="4" height="12" /&gt;&lt;/a&gt;&lt;a href="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/2654.clip_5F00_image0011_5F00_5BB96109.gif"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="clip_image001[1]" border="0" alt="clip_image001[1]" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/0511.clip_5F00_image0011_5F00_thumb_5F00_3B9E544C.gif" width="6" height="12" /&gt;&lt;/a&gt;&lt;a href="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/6874.clip_5F00_image0031_5F00_1B83478F.gif"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="clip_image003[1]" border="0" alt="clip_image003[1]" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/2063.clip_5F00_image0031_5F00_thumb_5F00_691F740F.gif" width="4" height="12" /&gt;&lt;/a&gt;&lt;a href="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/0820.clip_5F00_image0012_5F00_6FD27D92.gif"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="clip_image001[2]" border="0" alt="clip_image001[2]" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/2148.clip_5F00_image0012_5F00_thumb_5F00_4FB770D5.gif" width="6" height="12" /&gt;&lt;/a&gt;&lt;a href="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/5707.clip_5F00_image0032_5F00_2F9C6418.gif"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="clip_image003[2]" border="0" alt="clip_image003[2]" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/5314.clip_5F00_image0032_5F00_thumb_5F00_7D389098.gif" width="4" height="12" /&gt;&lt;/a&gt;&lt;a href="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/6874.clip_5F00_image0013_5F00_11BDE017.gif"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="clip_image001[3]" border="0" alt="clip_image001[3]" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/3731.clip_5F00_image0013_5F00_thumb_5F00_1F902612.gif" width="6" height="12" /&gt;&lt;/a&gt;&lt;a href="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/6371.clip_5F00_image0033_5F00_7F751954.gif"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="clip_image003[3]" border="0" alt="clip_image003[3]" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/1588.clip_5F00_image0033_5F00_thumb_5F00_5AE38BD0.gif" width="4" height="12" /&gt;&lt;/a&gt;&lt;a href="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/7444.clip_5F00_image0014_5F00_2667DAEA.gif"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="clip_image001[4]" border="0" alt="clip_image001[4]" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/7457.clip_5F00_image0014_5F00_thumb_5F00_492BA358.gif" width="6" height="12" /&gt;&lt;/a&gt;&lt;a href="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/2664.clip_5F00_image0034_5F00_420C66E0.gif"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="clip_image003[4]" border="0" alt="clip_image003[4]" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/2148.clip_5F00_image0034_5F00_thumb_5F00_61BB40A8.gif" width="4" height="12" /&gt;&lt;/a&gt;&lt;/b&gt;&lt;b&gt;&lt;/b&gt;&lt;/p&gt;    &lt;p&gt;Dato che oggi è stato rilasciata la preview 1 di ASP.NET MVC 2 ho deciso di aggiornare il progetto che avevo usato a Remix09 alla nuova versione per esplorare un po&amp;#39; delle nuove funzionalità.因为今天被释放的ASP.NET MVC 2预览1，我决定升级项目我以前Remix09新版本探索出的新功能位&amp;#39;。 (ASP.NET MVC 1.0 e ASP.NET MVC 2 possono coesistere side-by-side senza problemi) （ASP.NET 1.0和ASP.NET MVC的MVC的2可以共存并排而任何一方的问题） &lt;/p&gt;    &lt;p&gt;Nella Release Note è documentato come aggiornare manunalmente il progetto, modificando gli assembly referenziati e il web.config.在发行说明文件manunalmente如何更新项目，修改程序集引用和Web.config。 &lt;/p&gt;    &lt;p&gt;Nel mio caso, dopo aver scaricato ed installato i bit ho creato un progetto con il nuovo template per Visual Studio 2008 SP1, che vedete in figura :就我而言，后下载并安装了我创建了一个新模板的Visual Studio 2008 SP1的项目位，你在图片中看到： &lt;/p&gt;    &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/pietrobr/WindowsLiveWriter/IlnuovoASP.NETMVC2Preview1_A70B/image_2.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="clip_image005" border="0" alt="clip_image005" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/4621.clip_5F00_image005_5F00_242DE2DF.gif" width="399" height="223" /&gt;&lt;/a&gt;&lt;/p&gt;    &lt;p&gt;Quindi ho fatto un semplice taglia e copia dei folder che mi intersessavano, più qualche modifica:所以，我犯了一个简单的剪切和复制的文件夹，我intersessavano，另外还有一些变化： &lt;/p&gt;    &lt;ul&gt;     &lt;li&gt;AppData: che conteneva il database delle sessioni应用程序数据：含有数据库会话 &lt;/li&gt;      &lt;li&gt;il file remix09.css che ho messo nel folder Content remix09.css我把文件夹中的内容文件 &lt;/li&gt;      &lt;li&gt;il mio controller HomeController.cs我的控制器HomeController.cs &lt;/li&gt;      &lt;li&gt;Tutto il contenuto della cartella Model, che contiene i file per implementare il Repository per le sessioni ISessionsRepository.cs, la classe repository SessioniRepository.cs ed il file di Entity Framework per le cassi del mio modello您的模型，其中包含文件来实现会议的ISessionsRepository.cs库的全部内容，班级库SessioniRepository.cs和文件实体框架来对我的模型的库房 &lt;/li&gt;      &lt;li&gt;ho aggiunto la stringa di connessione al mio web.config我添加了连接字符串以我的web.config &lt;/li&gt;      &lt;li&gt;Ho sostituito il folder Views/Home con le view che avevo fatto余取代了我这样做了的文件夹视图/首页 &lt;/li&gt;      &lt;li&gt;Ho sostituito la pagina Views/SharedViews/Site.Master con quella usata nel vecchio progetto余取代了页面浏览量/ SharedViews / Site.master所使用的旧的项目 &lt;/li&gt;      &lt;li&gt;ho fatto il find &amp;amp; replace del namespace che usavo nel precedente progetto con il nuovo namespace, che nel mio caso si chiama Remix09Mvc2preview1 (il nome che ho dato al progetto).我的确发现和替换的命名空间，我在与新的命名空间，这对我来说，以前被称为Remix09Mvc2preview1项目中使用（这个名字我向项目）。 Attenzione alle views che se strongly-typed, come nel mio caso, contengono il riferimento al nome completo delle classi.注意事项的意见，如果强类型，因为在我的情况，包括对完整的类名称引用。 &lt;/li&gt;      &lt;li&gt;ho aggiunto nella sezione assemblies, nel web.config, il riferimento, prendendolo dal web.我在web.config节集会补充说，参考，从网络到它。 config del progetto vecchio, a System.Data.Entity che viene usato da Entity Framework配置旧设计的，它是由System.Data.Entity实体框架使用 &lt;/li&gt;   &lt;/ul&gt;    &lt;p&gt;Ed ecco la mia demo funzionare come prima :这里是我的工作才演示： &lt;/p&gt;    &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/pietrobr/WindowsLiveWriter/IlnuovoASP.NETMVC2Preview1_A70B/image_4.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="clip_image007" border="0" alt="clip_image007" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/8424.clip_5F00_image007_5F00_1AD4AE5C.gif" width="422" height="277" /&gt;&lt;/a&gt;&lt;/p&gt;    &lt;p&gt;&lt;b&gt;DataAnnotation: validazione&lt;/b&gt;&lt;b&gt; DataAnnotation&lt;/b&gt;&lt;b&gt;：验证 &lt;/b&gt;&lt;/p&gt;    &lt;p&gt;Una delle novità riguarda l&amp;#39;utilizzo del meccanismo delle DataAnnotation, già usato dai Dynamic Data e nei RIA Services, con cui posso aggiungere degli&amp;#160; attributi alla mia classe del Modello, nel mio caso ho un&amp;#39;unica classe che descrive una “Sessione”, dato che l&amp;#39;intera applicazione consente di gestire le sessione dell&amp;#39;evento Remix.一个改变涉及的DataAnnotation机制的使用，已被俄动态数据和服务，用于我可以将属性添加到我的模型类在我的情况，我有一个类，它描述了一个“会议”，因为整个应用程序允许您管理活动会议不怕。 &lt;/p&gt;    &lt;p&gt;Nella demo di Remix, potevo creare una nuova sessione, ma non veniva verificato se, ad esempio titolo e sessione fossero valori diversi da null.在演示的不怕，我可以创建一个新的会话，但没有查证，例如标题和本届会议的非NULL值。 &lt;/p&gt;    &lt;p&gt;Con ASP.NET MVC 2 ho un reference già aggiunto, come vedete dalla figura:在ASP.NET MVC 2我已经添加了一个参考，正如你在图中看到： &lt;/p&gt;    &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/pietrobr/WindowsLiveWriter/IlnuovoASP.NETMVC2Preview1_A70B/image_6.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="clip_image009" border="0" alt="clip_image009" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/8030.clip_5F00_image009_5F00_19DE8D89.gif" width="289" height="87" /&gt;&lt;/a&gt;&lt;/p&gt;    &lt;p&gt;Quindi, come con i Dynamic Data, posso scrivere una classe parziale, che andrò ad aggiungere al Model e che mi dà controllo server-side sulle proprietà della mia classe:因此，当与动态数据，我可以写一个局部类，我将添加的标准，使我对我的类的属性控制服务器端： &lt;/p&gt;    &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/pietrobr/WindowsLiveWriter/IlnuovoASP.NETMVC2Preview1_A70B/image_8.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="clip_image011" border="0" alt="clip_image011" src="http://community.icburner.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/vs2010tests.metablogapi/7357.clip_5F00_image011_5F00_2E63DD07.gif" width="452" height="159" /&gt;&lt;/a&gt;&lt;/p&gt;    &lt;p&gt;Ho creato una classe SessioneMetadata nella quale posso specificare delle regole di validazione per le proprietà della classe Sessione.我创建了一个类SessioneMetadata在我指定的类会议属性验证规则。 In questo caso l&amp;#39;attributo Required ed il Relativo ErrorMessage fanno si che se inserisco una sessione vuota abbia degli errori di validazione, per ora (:-) ) server-side, come vedete dalla figura, dove ho usato la stessa View, senza nessuna modifica, che ho usato con la versione 1.0 di ASP.NET MVC.在这种情况下所需的属性及其出错提示的意思是，如果我进入一个空会话已验证错误，现在(:-))服务器端，你可以看到这个数字，在那里我用同样的看法，没有，变化，我与版本的ASP.NET MVC 1.0使用。 &lt;/p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://community.icburner.com/aggbug.aspx?PostID=1986" width="1" height="1"&gt;</description><category domain="http://community.icburner.com/blogs/vs2010tests/archive/tags/MVC2/default.aspx">MVC2</category></item></channel></rss>