Some implicit extensions of ASP. NET 4.0

Source: Internet
Author: User
ArticleDirectory
    • Preapplicationstartmethodattribute
    • Buildprovider. registerbuildprovider
    • Buildmanager. addreferencedassembly
    • Config-free ihttpmodule Registration

ASP. NET 4.0 has been improved in many aspects. This ASP. NET 4.0 White Paper describes many changes and improvements to ASP. NET 4.0 mechanisms. In my blog, I also have several articles on modifying ASP. net4.0 features. However, as a completely new framework and runtime, there will certainly be a lot of internal APIs and extensions that will not be exposed so clearly. For example, I learned some very useful extensions in my normal development from the introduction of three hidden extensibility gems in ASP. NET 4.

Preapplicationstartmethodattribute

This new attribute allows us to specify a public static functionApplication_startPreviously executed this function. If your site hasApp_codeDirectory, this function will alsoApp_codeDirectoryCodeRun the command before compilation. In my intuition, this is a very useful extension point.

We must use this attribute at the Assembly level, that is, we usually use this attribute at the Assembly level.Assemblyinfo. CSMedium:

[Assembly: preapplicationstartmethod (typeof (someclasslib. initializer), "initialize")]

We need to specify the name of the static function in the type and type. This static function must be a public function without parameters and return values.

The most important thing about this function is that it can be used inApplication_startSo many tasks are being executedApplication_startAnd cannot be changed, for example, the compilation extension to be introduced below.

Buildprovider. registerbuildprovider

We wanted to registerBuildproviderBy adding web. config<Buildproviders>. In ASP. NET 4.0, we can workPreapplicationstartmethodattribute, Add a customBuildprovider.

Buildmanager. addreferencedassembly

In the. aspx/. aspcx andApp_codeThe code files under the directory must be dependent onProgramSet. In the past, we had to configure these sets in the web. config<Assemblies>The node is completed. Now, you just need to work with the above attribute and the new method to add these dependencies directly in the form of code.

Config-free ihttpmodule Registration

This is an absolute use of preapplicationstartmethodattribute, which is described in detail in Nikhil Kothari's article. Its main goal is to register the ihttpmodule by code without the Web. config.

In short, although it is just a simple attribute, it is very useful. When we develop a reusable framework, we will inevitably need to make many related configurations in the program to run the program. In the past, we only required users to use web. config to complete the process. However, if a user loses a configuration, the entire framework may fail to run. If we can complete these necessary configurations within our framework, this will greatly reduce the framework's use threshold.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.