What is ASP.NET?
Category: Programming | Posted date: 2023-04-12 19:46:19 | Posted by: Admin
ASP.NET is an open-source web framework created by Microsoft for building cutting-edge web services and applications that run on macOS, Linux, Windows, and Docker.
What is ASP.NET?
The ASP.NET web development platform provides the programming model, comprehensive software architecture, and range of services required to construct dependable web applications for desktop computers and mobile devices. ASP.NET is built on the HTTP protocol, which uses the HTTP commands and policies to establish browser-to-server communication.
A component of Microsoft's .Net platform is ASP.NET. The extensible and reusable components or objects found in the .Net framework are used to create the compiled codes that make up ASP.NET applications. The entire class hierarchy in the.Net framework can be used by these scripts. ASP.NET is used to build interactive, data-driven web applications that run online. It provides a variety of tools for putting together, organizing, and working with code to create HTML pages, including text boxes, buttons, and labels.
The code for an ASP.NET application can be written in any of the following languages:
- C#
- Visual Basic.Net
- Jscript
- J#
ASP.NET Web Forms Model
Using ASP.NET web forms, the event-driven approach of interaction is expanded to web applications. When the browser submits a web form to the web server, the web server responds with a complete markup page or HTML page.
All client-side user activities are transmitted to the server for stateful processing. The server begins the answers after analyzing the effects of client activities.
HTTP is a stateless protocol right now. The elements of the application state that are saved by the ASP.NET framework are as follows:
The page state is either the client's state or the information entered into each field on the web form. The session state, also referred to as the complete session state, is the data collected from all of the pages the user accessed and interacted with throughout the session. Let's illustrate the concept with the aid of a shopping cart.
The user adds items to a shopping basket. Things are chosen from one page, let's say the items page, and the price and total amount gathered are displayed on another page, let's say the cart page. All the data flowing from numerous pages cannot be controlled by HTTP alone. The server-side architecture and ASP.NET session state keep track of the data collected over the course of a session.
The ASP.NET Component Model
Several ASP.NET page building blocks are offered via the ASP.NET component model. In essence, it is an object model that explains:
- There are server-side equivalents of practically all HTML tags or components, including "form" and "input."
- Server controls that facilitate the creation of complicated user interfaces. the Gridview control or the Calendar control, for instance.
The.Net framework, which houses all web-related features, provides the foundation for the ASP.NET technology. The object-oriented structure that makes up the.Net framework. Pages make up an ASP.NET web application. An ASP.NET page is processed by the ASP.NET runtime system by IIS when a user requests an ASP.NET page.
The.asp page is converted by the ASP.NET runtime into an instance of a class that derives from the.Net framework's basic class page. As a result, every ASP.NET page and all of its elements, such as the server-side controls, are objects.
ASP.NET life cycle specifies, how:
- The pages are processed by ASP.NET to create dynamic output.
- The application is launched and its pages are processed.
- The pages are built dynamically by ASP.NET.
The ASP.NET life cycle is split into two groups:
The steps of the application life cycle are as follows:
- A user requests access to a page that is an application resource. This request is sent by the browser to the web server.
- Following the first request being received by a unified pipeline, the following things happen:
- It creates an object of the class ApplicationManager.
- To offer details about the resources, a HostingEnvironment class object is generated.
- The application's top-level elements are compiled.
- There are produced response objects. The creation and initialization of application objects such HttpContext, HttpRequest, and HttpResponse.
- The HttpApplication object is constructed and assigned to the request as an instance.
- The HttpApplication class handles the request's processing. This class generates many events in order to process the request
The server loads the requested page into memory, processes it, and then sends it to the browser. After that, it is erased from memory. There are methods and events available at each of these steps that can be overridden based on the requirements of the application. In other words, you can override the default code by writing your own.
All the controls on the page are organized into a tree hierarchy by the Page class. This control tree includes every element on the page, excluding the directives. By including trace= "true" in the page directive, you can examine the control tree. Under "directives" and "event processing," we will discuss page directives and tracing.
The page life cycle phases:
- Initialization
- Instantiation of the controls on the page
- Restoration and maintenance of the state
- Execution of the event handler codes
- Page rendering
Working knowledge of the page cycle facilitates the writing of code to make a given item occur at any step of the page life cycle. It also helps with the development of unique controls, the timely startup of those controls, and the use of control behavior codes.
Different stages of an ASP.NET page:
- Page request - In any scenario, the response is sent when ASP.NET gets a page request and determines whether to parse and assemble the page or whether a cached copy of the page already exists.
- Starting the page life cycle - The Request and Response objects are set at this point. The IsPostBack property of the page is set to true if the request falls under the category of an old request or postback. The UICulture attribute for the page is also set.
- Page initialization - At this point, the themes are applied and the controls on the page are given unique IDs by setting the UniqueID parameter. Postback data is loaded and the control settings are reset to their view-state values for each new request.
- Page load - Control properties are now set using the values of the view state and control state.
- Validation - The IsValid attribute of the page is set to true upon the successful completion of the Validate method of the validation control.
- Postback event handling - Invoking the relevant event handler depends on whether the request is a postback (old request).
- Page rendering - All controls and the page's view state have been saved at this point. The page runs the Render method for each control, and the output is written to the OutputStream class of the page's Response property.
- Unload - The rendered page is provided to the client, and all cleanup work and page properties, such as Respond and Request, are completed.
ASP.NET Page Life Cycle Events
The page raises certain events at each point of its life cycle that could be programmed. A function or subroutine that is bound to an event using declarative characteristics like Onclick or handle is known as an event handler.
The page life cycle events are as follows:
- PreInit - The page life cycle begins with the PreInit event. The IsPostBack attribute is checked to see if the page is a postback. It creates dynamic controls, sets and retrieves the values for profile property values, and sets the themes and master pages. The OnPreInit method can be overloaded to handle this event, or a Page PreInit handler can be made.
- Init - The control property is initialized by the init event, and the control tree is created. The OnInit method can be overloaded to handle this event, or a Page_Init handler can be made.
- InitComplete - The InitComplete event enables view state tracking. Every control activates view-state tracking.
- LoadViewState - The LoadViewState event enables the controls to load view state data.
- LoadPostData - The contents of every input field defined by the form> tag are processed during this stage.
- PreLoad - The OnPreLoad method can be overloaded to handle this event, or a Page_PreLoad handler can be made.
- Load - The load event for the page is raised first, and then all load events for child controls are raised recursively after that. The controls for the control tree are created. A Page Load handler can be created or the OnLoad function can be overloaded to handle this event.
- LoadComplete - After the page has finished loading, control event handlers are launched and page validation occurs. The OnLoadComplete method can be overloaded to handle this event, or a Page LoadComplete handler can be made.
- PreRender - Just before the output is rendered, there is a PreRender event. Pages and controls can make any updates by processing this event before the output is rendered.
- PreRenderComplete - PreRender assures that the pre-rendering step is complete because it fires recursively for all child controls.
- SaveStateComplete - The page's control state is saved. Information about personalization, control state, and view state is preserved. The markup for HTML is produced. By either adding a Page Render handler or overriding the Render method, this stage can be handled.
- UnLoad - The page life cycle ends with the UnLoad phase. Recursively raising the UnLoad event for each control before raising it for the page itself. All resources and references, including database connections, have been cleared up completely. The OnUnLoad function can be changed to handle this event, or a Page UnLoad handler can be made.
Final Thought
ASP.NET is a platform for online applications developed by Microsoft that enables programmers to build dynamic web pages. It allows you to easily develop web apps using a fully functional programming language, such as C# or VB.NET.
On top of HTTP, ASP.NET offers an abstraction layer upon which web applications can be constructed. It offers high-level entities within an object-oriented paradigm, such as classes and components.