ASP.NET supports various types of applications, including:
1. Web Forms: Traditional event-driven development model for building interactive web applications.
2. MVC (Model-View-Controller): A pattern-based framework that promotes separation of concerns and testability.
3. Web API: A framework for building HTTP-based APIs to enable communication between different applications.
4. ASP.NET Core: A cross-platform, high-performance, and modular framework for modern web apps.
5. Blazor: A framework that allows C# developers to build interactive web UIs using WebAssembly.
The ASP.NET page life cycle consists of several stages:
1. Initialization: Controls are initialized, and their properties are set.
2. Load: The page loads with its controls and state data.
3. PostBack Event Handling: Handles user interactions like button clicks.
4. Rendering: The page is converted into HTML and sent to the browser.
5. Unload: The page and controls are discarded from memory.
Understanding the page life cycle helps in writing efficient event-driven web applications.
ASP.NET Web Forms and ASP.NET MVC are two different approaches for building web applications:
1. Web Forms follow an event-driven programming model, while MVC follows the Model-View-Controller pattern.
2. Web Forms use ViewState to maintain state, whereas MVC does not use ViewState, making it lightweight.
3. MVC provides better control over HTML and JavaScript, making it more SEO-friendly.
4. Web Forms use a drag-and-drop approach, while MVC requires more manual coding.
5. MVC is better suited for large applications that require clean separation of concerns.
ASP.NET server controls are special components that run on the server and generate HTML output to be sent to the client browser. Some key server controls include:
1. Standard Controls: Buttons, labels, textboxes, etc.
2. Data Controls: GridView, Repeater, ListView for displaying data.
3. Validation Controls: RequiredFieldValidator, CompareValidator, etc.
4. Navigation Controls: Menu, SiteMapPath for navigating between pages.
5. Login Controls: Used for authentication and authorization.
ViewState is a built-in mechanism in ASP.NET Web Forms used to preserve the state of controls across postbacks. It is stored in a hidden field on the page and helps in maintaining user input:
1. ViewState is enabled by default and is useful for retaining data during postbacks.
2. It increases page size since it is stored as an encoded string in the HTML.
3. It is not suitable for storing large amounts of data.
4. Developers can disable ViewState for controls to optimize performance.
5. Unlike session state, ViewState is specific to a single page and does not persist across multiple pages.
Server.Transfer and Response.Redirect are both used for navigation between pages in ASP.NET, but they work differently:
1. Server.Transfer transfers the request from one page to another on the server-side, without changing the URL in the browser.
2. Response.Redirect sends an HTTP request to the browser, instructing it to navigate to a different URL.
3. Server.Transfer is faster since it avoids an extra round-trip to the client.
4. Response.Redirect is useful for redirecting to external websites.
5. Server.Transfer maintains the original request data, while Response.Redirect starts a new request.
PostBack is the process of submitting an ASP.NET page to the server for processing:
1. It occurs when a user interacts with a control that triggers a server-side event.
2. PostBack allows the page to maintain its state after form submission.
3. It is commonly used in Web Forms applications where controls maintain their values.
4. Developers can prevent unnecessary PostBacks using AJAX techniques.
5. ASP.NET uses ViewState to help retain control values during PostBack.
HTTP Modules in ASP.NET are components that execute during the request processing pipeline. They allow developers to modify or inspect HTTP requests and responses.
1. They implement the IHttpModule interface.
2. They are useful for handling authentication, logging, and response filtering.
3. They can be registered in the web.config file.
4. They execute for every request, unlike HTTP Handlers which handle specific types of requests.
5. Examples include authentication modules and session state modules.
HTTP Handlers in ASP.NET are responsible for processing incoming HTTP requests and generating appropriate responses. Some key points about HTTP Handlers:
1. They are classes that implement the IHttpHandler interface.
2. They are used for handling specific types of requests, such as images, XML, or JSON responses.
3. Custom HTTP Handlers can be created to handle requests efficiently.
4. They provide a way to process requests before the page life cycle begins.
5. Common handlers include ashx files for handling AJAX requests.
Purpose of Global.asax
It allows developers to respond to application-wide events raised by:
Notes
Session State Used to store user-specific information (like login details, cart items). Each user (browser session) gets a separate storage. Use Case: Personalizing experience, shopping cart, user profile info, etc
// Store value
csharpSession["UserName"] = "John"; // Retrieve value string userName = Session["UserName"].ToString();
Application State Used to store global data accessible by all users. Shared across all sessions. Use Case: Site-wide counters, shared settings, configuration data.
// Store value
csharpApplication["TotalVisitors"] = 100; // Retrieve value int count = (int)Application["TotalVisitors"];
Definition:
Postback is a round-trip from the client (browser) to the server and back to the same page. It's used to process events (like Button clicks) and update the page content accordingly.
When Does Postback Occur?
ASP.NET Controls are server-side components used to build interactive and dynamic web user interfaces in ASP.NET applications. They run on the server and render HTML to the client browser.
Example of ASP.NET Controls
<asp:TextBox ID="txtName" runat="server"></asp:TextBox><asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClick="btnSubmit_Click" /><asp:Label ID="lblMessage" runat="server" />
Server.Transfer("Page2.aspx");
The browser still shows the URL of the original page (e.g., Page1.aspx), but the content is served from Page2.aspx.
Response.Redirect("Page2.aspx");
The browser is instructed to make a new request to Page2.aspx, and the URL changes accordingly.
ASP.NET Web API is a framework provided by Microsoft for building HTTP-based services and APIs that can be accessed from a wide range of clients including browsers, mobile devices, desktop applications, and more.
Razor is a markup syntax used in ASP.NET for embedding server-based code (typically C#) into web pages. It is a core component of ASP.NET Web Pages, ASP.NET MVC, and ASP.NET Core. Razor allows developers to create dynamic and data-driven web content with minimal effort and cleaner syntax.
@ symbol to transition between HTML and server-side C# code, making it easy to read and write.Here’s a simple example of Razor syntax within a view:
<h1>Welcome, @Model.UserName!</h1>
<p>Today’s date is: @DateTime.Now.ToString("D")</p>
Entity Framework (EF) is an open-source Object-Relational Mapping (ORM) framework for ADO.NET, developed by Microsoft. It allows developers to work with a database using .NET objects, eliminating the need for most of the data-access code that developers usually need to write.
The Web.config file is a crucial configuration file used in ASP.NET applications. It contains settings and configurations that control how an ASP.NET web application behaves. These settings include security configurations, database connections, session states, error handling, and much more.
Caching is a technique used to store frequently accessed data in memory to improve the performance and scalability of web applications. In ASP.NET, caching allows pages, data, or parts of a page to be stored so that subsequent requests can be served faster.
Middleware plays a crucial role in how an ASP.NET Core application processes HTTP requests. It enables developers to:
public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { app.UseRouting(); app.UseAuthentication(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); }
Dependency Injection (DI) is a design pattern used in ASP.NET Core to achieve loose coupling between classes and their dependencies. Instead of creating instances of dependent classes manually, the framework automatically provides these dependencies, making code easier to manage, test, and scale.
ASP.NET Core has built-in support for Dependency Injection. It uses a built-in IoC container to register services and inject dependencies where needed. You configure services in the Startup.cs file using the ConfigureServices method.
Tag Helpers are a feature in ASP.NET Core that enable server-side code to participate in creating and rendering HTML elements in Razor views. They make Razor markup more readable and maintainable by allowing HTML-like syntax for dynamic content.
Tag Helpers are implemented as C# classes that target specific HTML elements. They run on the server and modify the HTML before it’s sent to the client.
Blazor is a modern web framework developed by Microsoft as part of ASP.NET Core. It enables developers to build interactive and rich web user interfaces using C# and .NET instead of JavaScript. Blazor uses a component-based architecture and runs in the browser via WebAssembly or on the server using SignalR.
Copyrights © 2024 letsupdateskills All rights reserved