How to use ASP.net to precompile a Web application to circumvent call latency method _ Practical Tips

Source: Internet
Author: User
Tags metabase
Since ASP.net, developers have been asking for a solution, and ASP.net 2.0 uses precompilation to provide an effective solution.

Pre-compiling options

When the application is first started, ASP. NET dynamically analyzes and compiles all the asp.net files (aspx pages). The running environment buffers the results of the compilation to better serve all future requests.

Starting an application for the first time after a server reboot or a Web server reboot means that the process will start again. Also, changes to any file of an application are detected by the system, and the first time the application is run after the file has changed will make the process happen again.

Many Web developers hate this kind of initialization latency. Precompilation avoids this delay by compiling the application (in advance).

command Line

By installing in the. NET Framework 2.0, the Aspnet_compiler.exe program can initiate precompilation. It is located under the Framework installation directory (the version number varies according to the version of the installed frame). The following is the default path for this program:

C:\\\\microsoft.net \\Framework\\v2.0.5072\\aspnet_compiler.exe

You can use-? This command parameter to view all of the program's parameter list, let me explain some of the available parameters:

M: This parameter indicates that you will use the complete IIS metabase path that the application will be precompiled. The path to the IIS metabase is the/lm/w3svc/1/root/application name.

V: Use the virtual IIS path that requires precompiling the Web application. The format of the virtual path is:/Application name.

P: Use the physical IIS path that requires precompiling the Web application. It is the full path that includes the drive name and points to the application directory. For example, c:\\inetpub\\wwwroot\\ the application name. V This parameter must be used with p, so the compiler can parse any application's root reference.

F: Indicates whether the target directory is to be overwritten.

U: Applications used to set up precompilation are updatable. This means that all tag files (ASPX, ascx, and so on) can be updated in the target directory.

TargetDir: The target directory used to precompile application files. The following command compiles an application with a virtual path and a specified target path: The ASPNET_COMPILER.EXE–V/application name c:\\ the target directory name.

If you do not specify a target directory, the resulting file is placed in the asp.net temporary file directory, just as the ASP.net runtime handles the compilation the first time the application is invoked. The default path for the temporary directory is as follows:

c:\\windows\\microsoft.net\\framework\\v2.0.50727\\temporary asp.net files\\ application name

Another benefit of precompiling is the ability to capture any errors that occur during the startup phase of the application. Errors are displayed in the tool, but the compilation process is not terminated.

Hide Source Code

Another by-product of precompilation is the ability to hide any or all of the application's source code. This means that other developers need to take advantage of the decompile or ilasm to get your code. That's all--precompilation allows you to distribute your application as a binary file.

There is no source code in the destination directory. All classes in the App_Code folder are compiled into one or more binaries, placed in the bin directory, and no source code files (. cs,. vb,. js, and so on) are available under the target directory. In addition, all master page files are compiled into the bin directory as hidden files. All the code and markup for ASPX, ascx, and ashx files, and the associated code-behind files, are placed in one or more assemblies in the bin directory.

The hidden source code is mixed. Other developers cannot view or change the application in any way-even web page tags. On the other hand, any changes to the application, regardless of size, require changes to the original source code, recompilation, and redeployment. This can be a time-consuming process, so it does not necessarily apply to all applications.

The updatable Command parameter (u) allows you to override this default behavior. Using this parameter means that all tag files (ASPX, ascx, and so on) are included in the output of the precompiled process. Once the application is deployed, these files can still be used for editing and updating. After the application is applied, small layout problems can be handled through the source file, so this is an ideal parameter.

Support for Visual Studio

Precompiling is optional when developing asp.net based applications using Visual Studio 2005. The Publish Web site (Publish Web sites) menu option allows you to push a Web site to another location as a precompiled application. In addition, there is a check box above that lets you set updatable options.

Summary

The precompilation option for ASP.net 2.0 allows you to precompile a Web application to avoid the first call to the application's latency (like normal compilation). In addition, it provides some security because the source code of the program is not visible in the result, and all content files can be hidden.
Related Article

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.