ASP.Net -Introduction, life cycle and Hello World program

ASP.Net – this is a web development platform created by Microsoft Corporation. It was released in 2002.

Latest version ASP.Net -4.6. designed to work with the HTTP protocol. This is a standard protocol used in all web applications.

ASP. Net applications can be created in various .Net languages. These include C #VB.NET and J #.

From this article about ASP.Net for beginners you will learn:

  • What is ASP?Net?
  • About the ASP lifecycle.Net;
  • About the life cycle of the ASP page.Net;
  • How to create a simple ASP program.Net.

What is it ASP.Net?

ASP.Net – this is a platform that is used for developing web applications. Basic ASP architecture.Net is shown below:

Architecture.The Net Framework includes the following components::

  1. Language-in .Net, web application development uses and C#;
  2. Library-.NET includes a set of standard class libraries. In particular, the Web library is used for developing web applications;
  3. Common Language Runtime (CLR) – a common language framework or CLI. It is used to run .Net programs. The CLR is used to perform key actions. Actions include exception handling and resource release (Garbage Collection).

Key features of ASP.Tips that are important for beginners:

  • Separation of design and code – makes it easier to maintain applications ASP.NET. The general file type is ASP.Net – aspx. Let’s assume that we have a web page named MyPage. aspx. It should be accompanied by another file named MyPage. aspx. cs, which contains part of the page code. So Visual Studio creates separate files for each web page: one for the design, and the second for the code.
  • State management – ASP.Net allows you to manage state. HTTP is known as a stateless protocol. Let’s take the shopping cart app from an online store as an example. When the user has decided which product they want to buy, they click “Add to Cart“.

The app must remember information about what the user has chosen to purchase. This is called remembering the current state of the app. The HTTP protocol does not support states. When the user goes to the product payment page, HTTP does not store information about the products in the shopping cart. To transfer them to the payment page, you need to add a code. This implementation may become more complex. But ASP.Net allows you to manage states: store items in the shopping cart and send them to the payment page.

  • Caching – ASP.Net implements the concept of caching. This improves the app’s performance. By caching pages that are frequently requested, you can store them in temporary storage. These pages can be extracted faster, reducing the response time. So caching can significantly improve the performance of the application.

Life cycle ASP.Net

When studying ASP.Net mvc 4 for beginners, it is important to know the application lifecycle. When the ASP application starts.Net, several steps are performed. This chain forms the life cycle of the application:

  1. Launch – application lifecycle ASP.NET it starts when the user executes a request directed to the web server for the ASP application.Net. This usually happens when the user goes to the main page of the app for the first time. During this time, there is a method called Application_Startthat runs on the web server. This method sets all global variables to their default values;
  2. Creating objects – creating an HttpContextHttpRequest, and HttpResponse on the web serverHttpContext is a container for the HttpRequest and HttpResponseobjects. The HttpRequest object contains information about the current request, including cookies and browser information. The HttpResponse object contains the response that is sent to the client;
  3. Creating an HttpApplication-this object is created on the web server. It is used to process each subsequent request addressed to the application. Let’s assume that we have two web applications. One is a shopping cart app, and the other is a news site. An HttpApplication object is created for each application. All further requests to each site will be handled by the corresponding HttpApplication instance.;
  4. Reset-This event is called before the application instance is deleted. At this time, you can use this method to manually reset any unmanaged resource.;
  5. End of application – at this stage, the application is finally unloaded from memory.

Page Lifecycle ASP.Net

When the ASP page is called.Net, it goes through a certain life cycle. The steps in this loop run until the response is sent to the user.

As part of this ASP article.Net for beginners let’s look at the sequence of page processing steps:

  1. Page Request – when a page is requested, the server checks whether it is being requested for the first time. If so, the page is created, the response is processed, and sent to the user. If the page is not requested for the first time, the cache is checked. If the page exists in the cache, the saved response is sent to the user;
  2. Page launch – at this stage, the Request and Response objects are createdThe Request object is used to store information that was sent when the page was requested. The Response object is used to store information that is sent back to the user;
  3. Page initialization – at this stage, all controls of the web page are initialized;
  4. Page loading – the page loads with all the default values. For example, if a text field should have a default value, it is loaded during page load;
  5. Validation – in some cases, validation can be set for certain forms. For example, you may be asked to confirm that a list item contains a specific set of values. If this condition is not met, an error should be displayed when loading the page;
  6. Event re-processing-occurs if the page loads again. This happens in response to the previous event. If the user clicks on the send data button on the page. In this case, the same page is displayed again. Then the repeated event handler is called;
  7. Page display-occurs before the response is sent to the user. All information about the form is saved, and the result is sent to the user as a complete web page.;
  8. Upload – after the page is sent to the user, there is no need to store web form objects in memory anymore. Thus, the unloading process involves removing all unnecessary objects from memory.

The “Hello World” program in ASP.Net

Learning ASP.Net web forms for beginners is best to start by creating a simple “Hello, World” application. To do this, follow these steps.

Step 1: Create a new project in Visual Studio. After starting Visual Studio, select the menu item New> Project:

Step 2: The next step is to select the project type-web application ASP.NET. Here you need to specify the name and location of the project.

  1. In the project dialog box, select “Web” in the left panel. And then “Web application ASP.Net“;
  2. Enter the app name and storage location;
  3. Click on the “OK” button for Visual Studio to create a project.

Step 3: In the next window, select the type of web application. ASP.NET, which should be created. We want to create a simple web form application.

  • Select the project type – “Empty“;
  • Select the option “Web form“. After that, shared folders will be added. They are required to create the basic web form application.;
  • At the end, click on the “OK” button so that Visual Studio creates the application.

If you follow the above steps in the ASP manual.Net for beginners, then you will get the result shown in the figure below in Visual Studio:

TheDemoApplication application will appear in the “Solution explorer. It contains two project files, as shown in the figure above. One of the key project files is Global. asax. cs. It contains application-specific information. In this file, you can initialize all variables by defining default values for them.

Step 4: Now it’s time to add the web form file to the project. This is a file that will contain all the project code.

  • Right-click on DemoApplication;
  • Select from the context menu:Add> Web Form>.

Step 5: In the next window, enter a name for the web form. In our case, this will be a Demo.

  • Click OK:

Visual Studio will automatically create a Demo web form and open it.

Step 6: The next step is to add a code that will display “Hello World“. You can do this by adding one line of code to the Demo. aspx file:

Explanation of the code:

  • The Response object in ASP.Net is used to send information back to the user. In this case, we use the Write method of the Response objectto write the text “Hello World“. Markers are used to add specific code

If you follow all the steps listed in this article about ASP.Net mvc for beginners and run the created program in Visual Studio, you will get the following result:

The browser window displays the phrase “Hello, World“.

Leave a Reply

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

You May Also Like
Read More

Web projects

So far, we’ve only covered how you can create websites without any project files. The advantage of project-free development…