App Model ASP.NET

Difference between applications ASP.NET and feature-rich client applications, which makes a lot of sense when analyzing the execution model ASP.NET. Unlike Windows apps, the end user never launches the app ASP.NET directly. On the contrary, the user starts the browser and requests a specific URL (such as via HTTP. The web server receives this request. When debugging an application in Visual Studio, only the local test server is used. The application is deployed using an IIS web server.

The web server has no concept of separately existing applications — it just passes the request to the worker process ASP.NET. However, the workflow is ASP.NET carefully separates code execution into different application domains based on the virtual directory. Web pages that reside in the same virtual directory (or one of its subdirectories) are executed in the same application domain. Web pages from different virtual directories run in different application domains.

Application Domain

An application domain is a boundary set by the CLR that ensures that one application cannot influence another application (or see data stored in its memory). The following characteristics are a direct consequence of the application domain model:

  • All web pages in a single web application share the same in-memory resources — global application data, session data for individual users, and cached data. This information is not directly available to other apps ASP.NET or ASP.
  • All web pages in the same web application share the same basic configuration settings. However, you can configure some configuration settings in separate subdirectories of the same virtual directory. For example, you can set only one authentication mechanism for a web application, regardless of how many subdirectories it has.On the other hand, each directory may have different authorization rules to determine exactly who will be allowed access to different groups of pages.
  • All web applications generate global application events at various stages (when the application domain is created for the first time, when it is destroyed, etc.). Using the code in the global.asax file located in the application’s virtual directory, you can attach event handlers that will respond to these global application events.

In other words, a virtual directory is a basic group structure that defines the boundaries of an application ASP.NET. Valid ASP application.NET may well contain a single web form (an. aspx file). However, basically every application ASP.NET it can include all the components listed below:Web forms (. aspx files)

These components are fundamental to any application ASP.NET.Master pages (. master files)

These components are templates that allow you to build multiple web forms with the same structure.Web services (. asmx files)

These components allow you to share useful functions with applications that are located on other computers and platforms.Separated code files

Depending on the code model used, separate source code files may also be present. If these files contain C# code, then they have the extension .cs.Configuration file (web. config)

This file contains many application-level settings that are responsible for configuring everything from security to debugging and state management.Global.asax file

This file contains event handlers that respond to global events of the application (such as its first launch).Other components

These include compiled assemblies that contain either individual components developed by you, or third-party components that have useful functionality. These components allow you to separate business logic from data access logic and create special controls.

Naturally, the virtual directory can contain a large number of additional resources that will be used by web applications ASP.NET including style sheets, images, XML files, and so on. In addition, you can extend the model ASP.NET, developing specialized components-HTTP handlers and HTTP modules that can be embedded in the application and take part in processing web requests ASP.NET.

Different types of files belonging to different handlers may well be stored in the same virtual directory. As a simple example, you can give the situation with mixing files .aspx and .asp. In a more complex example, the environment ASP.NET 4 can be configured to handle file requests .aspx, a ASP.NET 3.5 – for processing requests to files with some other extension.

App lifetime

To create app domains ASP.NET uses the lazy initialization technology. This means that the domain for a web application is created when a request for a page in that application is first received.

The application domain may terminate for various reasons, including the web server itself. However, as a rule, applications are automatically restarted in new application domains in response to errors or configuration changes.

If you change the application environment ASP.NET automatically updates app domains. One example is to modify the web. config file. Another example is replacing an existing web page file or an assembly DLL file. In both of these cases ASP.NET starts a new application domain to process all future requests, and keeps the existing application domain running until all pending requests (including those in the queue) are processed.

Comparison of application domains and application pools

In IIS, the behavior of web applications is configured using application pools. The app pool parameters determine the version .NET that the application should receive, how long it can remain idle before it finishes, whether it should restart automatically when certain errors occur, and so on.

The concept of an application pool is similar to that of application domains, but is a bit broader. The difference is as follows. Each IIS application pool can configure one or more web applications. At runtime, each web application typically consists of a single application domain. Formally, application pools are an IIS configuration tool, and application domains are part of the .NET infrastructure.

Updating apps

One of the most notable features of the execution model is ASP.NET The advantage is that it allows you to update the web application without restarting the web server and without worrying that it may cause harm to existing clients. This means that files in the virtual directory can be replaced, added, and deleted at any time. ASP.NET then it performs exactly the same transition to the new application domain as in the case of changing the web.config configuration file.

The ability to update any part of the application at any time without interrupting the execution of existing queries is a powerful tool. However, it is important to understand what exactly is in the architecture ASP.NET makes it available. Many developers mistakenly assume that it is a smooth transition to a new application domain ASP.NET allows the CLR environment. But in fact, the CLR always locks assembly files when it executes them.

To get around this restriction, ASP.NET doesn’t use the files themselves ASP.NET located in the virtual folder. Instead, at compile time, it applies a technique called shadow copyand creates copies of all files in the directory. c:\Windows\Microsoft.NET\Framework\[version]\Temporary ASP.NET Files. Workflow ASP.NET loads assemblies from this directory, which means that these particular assemblies will be blocked.

The second notable feature is the ability to ASP.NET detect changes in source files. It’s pretty clear here — ASP.NET it simply relies on the ability of the Windows operating system to monitor directories and files and send immediate notifications of changes. ASP.NET maintains an active list of all assemblies uploaded to the application-specific domain, and uses monitoring code to monitor changes and perform appropriate actions.

ASP.NET It can use files stored in the Global Assembly Cache (GAC), which is a computer-accessible repository that contains all the basic ingredients, such as assemblies for a class library .NET Framework. You can also put your own assemblies in the GAC, but this usually complicates the deployment and management of web applications.

Application directory structure

Every web application should have a well-designed directory structure. Whatever directory structure the developer designs, ASP.NET offers several special-purpose directories:

BinThis directory contains all pre-compiled assemblies .
NET (usually in the form of DLL files) that this web application uses ASP.NET. 
These assemblies can include pre-compiled web page classes, as well as other assemblies referenced by these classes.
App_CodeIf you use the project model for developing a web application in Visual Studio, rather than the more common website model, the Bin directory will also contain an assembly with the compiled code of the entire web application. 
This assembly has the same name as the app, for example WebApplication1.dll.
App_GlobalResourcesThis directory contains source code files that are dynamically compiled for use in this application. 
These code files usually substitute individual components, such as a login component or a data access library. 
Dynamically compiled code never appears in the Bin directory, because ASP.NET places it in temporary directories designed specifically for this purpose.
App_LocalResourcesThis directory serves the same purpose as the App_GlobalResources directory, but only the resources contained in it are accessible only to the pages in the application for which they are specifically intended.
App_WebReferencesThis directory stores links to web services that the web application uses, including WSDL files and discovery documents.
App_DataThis directory is used to store data, including SQL Server Express database files and XML files. 
Of course, you can save data files in other directories.
App_BrowsersThis directory contains browser definitions stored in XML files. 
These XML files define the ability of client browsers to perform various visualization-related actions. 
Although ASP.NET It does this globally (across the entire computer). The App_Browsers directory allows you to configure this behavior for individual web applications.
App_ThemesThis directory stores themes that can be used in this web application.
Special catalogs ASP.NET
Leave a Reply

Your email address will not be published. Required fields are marked *

You May Also Like