Understanding ASP.NET Dynamic Compilation

In order for your Web application to service requests, ASP.NET must first parse and compile the code of your Web application into one or more assemblies.Quando o código é compilado, é traduzido para uma representação independente de liguagem e de CPU chamada Linguagem Intermediária da Microsoft (MSIL - Microsoft Intermediate Language).Em tempo de execução, MSIL roda no contexto do Framework .NET, que traduz para instruções específicas de CPU do processado do computador que está rodando a aplicação.

Compiling on First Request

By default, ASP.NET Web pages and code files are compiled dynamically when users first request a resource, such as an ASP.NET page (.aspx file), from a Web site.Depois que páginas e arquivos código foram compilados na primeira vez, os recursos compilados são armazenados em cache, para que solicitações para a mesma página subsequentes sejam extremamente eficientes.

ASP.NET supports the dynamic compilation of ASP.NET pages (.aspx files), ASP.NET Web services (.asmx files), ASP.NET HTTP handlers (.ashx files) and ASP.NET application files (Global.asax), as well as other files, such as source code and class files.For more information about ASP.NET file types, see Tipos de arquivo de sites da Web.For more information about the ASP.NET compilation process, see the "Compilation Life Cycle" section of Ciclo de Vida do Aplicativo ASP.NET uma visão geral para o IIS 5.0 e 6.0.

Recompiling on Change

Any changes to a dynamically compiled file will automatically invalidate the file's cached compiled assembly and trigger recompilation of all affected resources.The next time a request to the code is made, ASP.NET recognizes that the code has changed and recompiles the affected resources of the Web application.This system enables you to quickly develop applications with a minimum of compilation processing overhead.(Note that depending on the change to the resources, the result can range from recompiling a single page to recompiling the entire Web site.)

Compilation Dependencies

When the first request is made to an application, ASP.NET compiles files in a specific order.O primeiro item a ser compilado são os itens referentes ao níveis altos.Após a primeira solicitação, o itens de alto nível são recompilado apenas se uma dependência muda.

Top-level items include the App_GlobalResources folder, the App_WebResources folder, profile properties, the App_Code folder, and the Global.asax file.After the top-level items are compiled, ASP.NET compiles additional items.These items include the App_LocalResources folder, individual ASP.NET pages (.aspx files), ASP.NET user controls (.ascx files), ASP.NET HTTP Handlers (.ashx files), and ASP.NET HTTP modules (.asmx files), as well as themes, master pages, and other source files.

For more information, see Layout de Site Web do ASP.NET and the "Compilation Life Cycle" section of Ciclo de Vida do Aplicativo ASP.NET uma visão geral para o IIS 5.0 e 6.0.

Compilation Output

When your code is compiled, the resulting assemblies are cached in a folder on the server.This folder requires appropriate permissions so that your code compiles and runs correctly.You can configure both the compilation folder location and the permissions under which your code compiles and operates.

Compilation Folder Location

By default, when you compile a Web application the compiled code is placed in the Temporary ASP.NET Files folder.This folder is a subdirectory of the location where you installed the .NET framework.Typically, the location is the following:

%SystemRoot%\Microsoft.NET\Framework\versionNumber\Temporary ASP.NET Files

Compilation Folder Required Permissions

The .NET installation process creates the Temporary ASP.NET Files folder and assigns access permissions to the ASP.NET local user account, which has the high-trust permissions needed to access your compiled code.If you modify your configuration or account settings, you must make sure that the account you use has high-trust permissions to the Temporary ASP.NET Files folder.For additional details, see Como: Executar o processo de trabalho em uma conta de usuário.

Compilation Folder Configurability

ASP.NET creates a discrete subfolder under the Temporary ASP.NET File folder for each application.You can configure the root location using the tempDirectory attribute of the compilation section of the configuration file.This optional attribute enables you to specify the directory to use for temporary file storage during compilation.The default is an empty string ("").In the case of an empty string, and if the current process has the required access permissions, the files are stored in the following directory:

%FrameworkInstallLocation%\Temporary ASP.NET Files

For more information, see Elemento compilation (Esquema de configurações ASP.NET) and the TempDirectory property of the CompilationSection.

Multiple Language Support

ASP.NET 2.0 supports multiple programming languages in the same Web application.In the App_Code directory, you can specify a subfolder for each language, such as C# and Visual Basic.ASP.NET will create a separate assembly for each subfolder.Para obter mais informações, consulte Pastas de código compartilhado em sites da Web ASP.NET e Demonstra Passo a passo: Desenvolver sites da Web usando várias linguagens de programação.

Dynamic Compilation Advantages and Disadvantages

ASP.NET dynamic compilation enables you to modify your source code without having to explicitly compile your code before deploying your Web application.If you modify a source file, ASP.NET automatically recompiles the file and updates all linked resources.The IIS server does not have to be restarted for the changes to take effect unless the <processModel> section has been changed.Additionally, you can extend the ASP.NET build system by creating custom build providers for new file types that are called during compilation.The dynamic compilation benefits of the ASP.NET build system are backward compatible with older ASP.NET application structures and types as well.

There are certain capabilities that dynamic compilation does not offer.Dynamic compilation can mean slower initial response time for users, because pages and code files must be compiled the first time they are requested.This may be an issue particularly on large sites that are updated frequently.Dynamic compilation does not offer a means to identify compile-time bugs before users access a site.Also, dynamic compilation does not provide the ability to create a compiled version of the site that can be deployed to a production server without source code.If any of these issues are concerns for your Web applications, you can precompile your Web site.For details information, see ASP.NET Precompilation Overview.

Consulte também

Tarefas

Como: Proteger um aplicativo ASP.NET em um servidor compartilhado

Conceitos

ASP.NET Impersonation

ASP.NET Required Access Control Lists (ACLs)

Tipos de arquivo de sites da Web

Layout de Site Web do ASP.NET

Referência

CodeGenDir

Outros recursos

Visão geral da Pré-compilação do Site da Web ASP.NET