With the public test of VS2010, ASP. NET4.0 has also become our sights. What does ASP. NET4.0 bring to us? In what ways will we improve our productivity?
When do you need to use ASP. NET4.0 to develop your website programs?
- More Strict compliance with web standards
- More fluent webform Development
- Requires better search engine optimization
- It is necessary to learn and correct some poor designs, which may even exist before ASP. NET1.0 is released.
- You need to rebuild existing functions to support server farm or cross-application domains
- You need to adjust and reorganize. NET into a whole
You do not need to learn complex design patterns or various SEO skills, or even the ability to refactor code. Forget the complicated rules and dogma. With the various convenient and practical new functions provided by ASP. NET4.0, you can easily develop/upgrade high-quality programs that keep pace with the times. All of this needs to start from here:
- Download and install VS2010
- Http://www.microsoft.com/visualstudio/zh-cn/products/2010/default.mspx#compare
- Before installation, you must uninstall the previous test version, including. NET Framework 4. The new version of VS2010 contains a large number of updates, which are not compatible with the previous test version.
- New predefined interface:
VS2010 brings a new predefined setting: Web Development (Code Only), as shown literally, it is designed for web Development, but unlike the general Web Development mode, it targets developers who like handwriting code. It makes VS look more like a simple IDE:
As for whether you like it or not, you will love radish and vegetables... (I still like full screen mode ..)
VS2010 has made a lot of changes to the ASP. NET project type. The specific changes are as follows:
- ASP. NET Web Service Application is completely removed
- The WCF Service Application brought by. Net3.0 is moved to the WCF projects
- Two Dynamic Data-related projects brought about by. Net3.5 SP1 are changed to names that are easier to understand. For example, Dynamic Data Web Application replaces the previous Entity Framework with LINQ to SQL.
- The MVC project has a new choice called ASP. NET MVC2 Empty Web Application. New ASP. NET MVC2 Empty Web Application project will create the following content: Standard Directory (Empty), blank global. asax file, web. config File, standard jQuery and ms ajax library. ASP. NET MVC2 Web Application project will generate a workable website, implement a simple membership model, generate and use master page, error page, and the required content page, you can also generate a test project example. This is very helpful for beginners of MVC and can fully use MVC functions.
In VS2008SP1, the default web. config file code contains 139 lines. In ASP. NET4.0, the web. config file contains only 6 lines:
The principle is very simple. The ASP. NET Team reconstructed the web. config file and wrote general settings into the default machine-level web. config. There are only two configuration items that need to change frequently.
- The debug value is set to true by default in the Web Application project and false by default in the Web Site project.
- The values of targetFramework can be set to 4.0, 3.5, 3.0, and 2.0. This option is recognized by IIS and automatically assigned to the corresponding Framework version of the ASP. NET program pool.
- Intelliisense does not work in earlier web. config versions. You can delete the namespace (xmlns) attribute of configuration in the original web. config.
* Hierarchical structure of the. config file
In the new config file definition, a series of functions such as Dynamic Data, routing, and charting are all enabled by default.
The relationship between different levels of config files is very similar to that of CSS files. Simply put, the closer you are, the higher the config weight, that is, the lowest-layer machine. config has the lowest weight. The web. config in your new web project has the highest weight.
- The root config file is machine. config, which is located in C: \ Windows \ Microsoft. NET \ Framework \ v4.0.xyz \ Config
- Machine-level web. the directory where the config file is located, which is located in the machine. the config file defines the default values of some web-specific nodes, that is, in the previous ASP.. NET. the values in the config file.
- In the same directory, you will find the following files: web_hightrust.config, web_mediumtrust.config, web_lowtrust.config, and web_minimaltrust.config. If the trust level of your site is not "FULL", the corresponding config file will be used as the default value.
- In the project you create, a web. config file is generated by default, which is also known as the web. config file.
- You can add a web. config file in any directory of your project. The value in this file overwrites the value in the project root directory. You can use this feature to perform functions such as permission restrictions.
Config Transformation Files
This new function is used to cope with the problem that the same website needs different web. config files on different servers, for example, different connectionstring files. In the past, it was difficult for us to maintain these different web. config File (in my project, to solve this problem, I used com to build a registry and write the corresponding information in the registries of different machines ), now, with this new function, we can solve and solve this problem in a unified way through programming (based on XPATH technology ). You only need to right-click the web. config file and select "Add Config Transforms.
Programmers who have used ASP should be familiar with this file. This file is used to record all the browsers to be used and the features supported by these browsers (for example, whether activeX is supported ).
In. NET2.0, Microsoft splits browsercap. ini into a series of *. browser files. When receiving a request, we can find the corresponding browser file based on the browser file initiated by the request to obtain the browser's capabilities. The data will be passed to the HttpBrowserCapabilities object, so we can use the data.
All browser files can be found in C: \ Windows \ Microsoft. NET \ Framework \ v2.0.50727 \ CONFIG \ Browsers. It is actually quite complete.
Splitting a file into a series of files makes maintenance more difficult, but the reason for doing so does not seem to be difficult to guess: Microsoft wants a series of browsers to use the same file, such as ie. browser, mozilla. browser.
In. in NET4.0, Microsoft continued to follow this idea and updated these files in a wide range to support popular browsers, especially mobile browsers: iPhone, Windows PhoneOS, and Android, these browsers are not simply processed as wap browsers. For desktop browsers, Firefox, Chrome, and Safari are also supported.
This is a good practice, but the problem arises. Do we have to wait until every new. Net Framework is released to obtain these new files? Of course, the answer is no.
Today, browsers are evolving rapidly, and IE9, Opera 10.5, Gecko 1.9.3, and new IE for mobilephone are coming soon. If we want to support these new browsers, we have four options:
- Manually update these browser files or create new browser files.
- Create a new browser file and add it to the App_Browser folder of your site. But this is only valid for your current site.
- Extends the existing browser capabilities provider.
- Create a custom browser capabilities provider to replace the existing one.
You can choose how to solve this problem based on your resources or website architecture. We recommend that you use the custom browser capabilities provider to solve the problem. Although more code is required, the later update will be easier once completed. This means that you can support new browsers more quickly.
But in any case, it is difficult to support a new browser, But. NET4.0 brings us the latest browser support file and a scalable method.
Any ASP. NET developer is familiar with @ Page labels. The good news is that ASP. NET4.0 is fully compatible with the 42 Attributes provided by previous versions. Better news is that ASP. NET4.0 has also brought six new attributes to cope with increasingly complex development requirements:
- ClientIDMode, as its name implies, is used to define ASP. NET will generate the control Client ID. If you are a front-end developer, you will understand how convenient it will be to control the generation of client IDs. Possible values are AutoID (default/current), Predictable, Static, and Inherit.
- ClientTarget is used to define the browser to which the page will be executed. This will cover the automatic browser Recognition Feature provided by ASP. NET. For example, we only need to support IE or FIREFOX.
- Metadedescription, as its name implies, is used to generate the description tag of the meta on the page. In my opinion, it only provides a more official method and method to standardize this process.
- As the name suggests, MetaKeywords is used to generate the keywords tag of meta.
- TargetSchema is used to define the schema required for the verification page. This label is only used for identification and will not actually be executed. It can be seen as a code annotation.
- ViewStateMode is used to define whether the VIEWSTATE of a page is opt-in or opt-out (default.
In general, it has not changed much and provides some very popular features.
Generate more pure and standard HTML code
This is always ASP. NET. ASP. the html code generated by NET1.1 basically does not comply with the standard. NET2.0 has been improved. xhtmlConformance is introduced in config to define the standard HTML code that the control will generate. The default value is XHTML1.0 Transitional standard (Transitional ). Correspondingly, we can set it to XHTML1.0 Strict or select generate with ASP. NET1.1 the same HTML code (Legacy, mainly used for compatibility from ASP. NET1.1 ).
Unfortunately, websites running in Legacy mode and ASP. net ajax is not compatible, and although Transitional and Strict modes are compatible with the XHTML standard, the generated code is also very unfriendly to CSS. For example:
- Menu uses table output instead of UL/OL.
- The control attributes of the server, such as border = 0 or disabled = disabled, are mandatory and cannot be removed.
- For controls that support template, you can customize the code in the template, but you cannot remove the table label at the outermost layer.
ASP. the ListView, DataPager, and CSS Control Adapters controls brought about by NET3.5 provide a transitional solution, ASP. NET4.0 fully integrates them into the new version of System. web, so that Microsoft can enable ASP. NET4.0 can be as friendly as possible to CSS. Undoubtedly, generating clean HTML tags is one of the important goals of ASP. NET4.0.
- ControlRenderingCompatibilityVersion
Like xhltmlComformance, ASP. NET4.0 brings this new attribute to web. config. When set to 3.5, everything will be the same as the original, but when you set to 4.0, the control will output HTML code in a completely new mode:
- XhtmlConformance is set to Strict
- Menu will be output in UL/OL format
- Extra HTML properties will be removed, and even the validation font color will not be set to red.
- You can use the RenderOuterTable attribute on the control to control whether to output the peripheral table labels.
In my opinion, this is good news for those who are used to controls. Microsoft has done a lot of work for you.
List some new details
- Built-in <asp: chart>
- Three new Redirect Methods: Response. RedirectToRoute (HTTP302), Response. RedirectToRoutePermanent (HTTP301) and Response. RedirectPermanent (HTTP301)
- The HTML encoded string of Inline.
- Easier Routing configuration
This is probably the case. You are welcome to discuss it further.