Use ASP.NET as a handy way to precompile Web applications to avoid invocation delays

  • 2020-05-12 02:30:32
  • OfStack

Since the launch of ASP.NET, developer 1 has been asking for a solution, and ASP.NET 2.0 provides an effective solution with precompilation.

Precompile options

On the first launch of the application, ASP.NET dynamically analyzes and compiles all the ASP.NET files (aspx pages). The runtime environment buffers the compiled results to better serve all future requests.

Starting the application for the first time after a server restart or an Web server restart also means that the process starts over again. Furthermore, any changes to the application files are detected by the system, and running the application for the first time after the file changes can make this process happen again.

Many Web developers hate this initialization delay. Precompilation avoids this delay by compiling the application (up front).

The command line

You can start precompilation by installing the aspnet_compiler.exe program in the.NET framework 2.0. It is located in the framework installation directory (the version number will vary depending on the version of the framework you installed). Here is the default path:

C:\\\\Microsoft.NET \\Framework\\v2.0.5072\\aspnet_compiler.exe

You can use -? This command argument looks at a list of all the arguments for the program, and I'll explain some of the arguments that are available:

m: this parameter indicates that you will use the full IIS metadata path that the application will precompile. IIS yuan database path is/LM W3SVC / 1 / Root/application name.

v: use the virtual IIS path that requires precompilation of the Web application. The format of the virtual path is :/ application name.

p: use the physical IIS path that requires precompilation of the Web application. It includes the drive name and the full path to the application directory. For example, c:\\inetpub\\wwwroot\\ application name. The v parameter must be used with p1, so the compiler can resolve the root reference for any application.

f: indicates whether the target directory should be overwritten.

u: used to set precompiled applications to be updatable. This means that all tag files (ASPX, ASCX, and so on) can be updated in the target directory.

targetDir: target directory for precompiling application files. The following command precompiles an application with the virtual path and the specified target path: aspnet_compiler.exe, v/application name c:\\ target directory name.

If the target directory is not specified, the result file will be placed in the ASP.NET temporary file directory, just as the ASP.NET runtime handles compilation 1 when the application is first invoked. The default path of the temporary directory is as follows:

c:\\Windows\\ Microsoft.NET \\Framework\\ v2.0.50727 \\Temporary ASP.NET Files\\

Another benefit of precompilation is the ability to catch any errors that occur during application startup. The error is displayed in the tool, but does not terminate the compilation process.

Hidden source code

Another byproduct of precompilation is the ability to hide any or all of the application source code. This means that other developers need to use a decompiler or ilasm to get your code. That's it -- precompilation lets you distribute your application as a base 2 file.

There is no source code in the target directory. All the classes in the App_Code folder are compiled into one or more binary files in the bin directory. There will be no source code files in the target directory (.cs,.vb,.js, and so on). In addition, all home page files are also compiled into the bin directory as hidden files. All code and tags for ASPX, ASCX, and ASHX files, as well as related code hiding files, are placed in one or more assemblies in the bin directory.

Hiding the source code is a mixed blessing. Other developers cannot view or change the application in any form -- not even the Web page tag. On the other hand, any changes to the application (large or small) require changes to the original source code, recompilation, and redeployment. This can be a 10-minute process, so it doesn't necessarily work for all applications.

The updatable command parameter (u) allows you to replace this default behavior. Using this parameter means that all markup files (ASPX, ASCX, and so on) are included in the output of the precompile process. Once the application is deployed, these files can still be used for editing and updating. After the application has been applied, small layout problems can be handled by the source file, so this is an ideal parameter.

Visual Studio support

Precompilation is optional when developing applications based on ASP.NET using Visual Studio 2005. The "publish Web site (Publish Web Site)" menu option allows you to push the site to another location as one precompiled application. In addition, there is a check box above to let you set updatable options.

conclusion

The ASP.NET 2.0 precompile option allows you to precompile Web applications to avoid the delay of first calling the application (compile 1 like 1). In addition, it provides a definite security, because the source code of the program is not visible in the results, and all content files can be hidden.

Related articles: