Exploring ASP.NET


Exploring ASP.NET Interview with follow-up questions

1. What is ASP.NET and what are its main features?

ASP.NET Core is Microsoft's modern, cross-platform, open-source framework for building web applications and APIs. It is the successor to classic ASP.NET and runs on .NET 8/9 (LTS).

Main features:

  • Cross-platform: Runs on Windows, Linux, and macOS — unlike legacy ASP.NET which was Windows-only.
  • Unified programming model: Supports MVC, Razor Pages, Blazor (Server, WebAssembly, and Auto render modes), and Minimal APIs within a single framework.
  • Minimal APIs: Lightweight HTTP endpoints with minimal ceremony, ideal for microservices.
  • Built-in Dependency Injection: First-class DI container baked into the framework.
  • Middleware pipeline: Request processing configured as a composable middleware pipeline in Program.cs.
  • Performance: Among the fastest web frameworks in TechEmpower benchmarks; Kestrel is the high-performance built-in web server.
  • Security: Built-in support for authentication (JWT, cookies, OAuth2/OIDC), authorization policies, data protection, HTTPS enforcement, and CORS.
  • Cloud and container-ready: Designed for Docker/Kubernetes; integrates with Azure and .NET Aspire for cloud-native orchestration.
  • Hot reload: Supports hot reload during development for faster iteration.
↑ Back to top

Follow-up 1

Can you explain the difference between ASP.NET Web Forms and ASP.NET MVC?

ASP.NET Web Forms and ASP.NET MVC are both frameworks for building web applications with ASP.NET, but they have different approaches and architectures.

ASP.NET Web Forms:

  • Web Forms is a page-based framework where each page represents a separate unit of work.
  • It uses a stateful programming model, where the state of controls is automatically maintained between postbacks.
  • It has a rich set of server controls and event-driven programming model.
  • It follows a RAD (Rapid Application Development) approach, making it easier to build complex UIs quickly.

ASP.NET MVC:

  • MVC (Model-View-Controller) is an architectural pattern that separates the application into three main components: the model, the view, and the controller.
  • It follows a stateless programming model, where the state is not automatically maintained between requests.
  • It provides more control over the HTML markup and allows for cleaner and more testable code.
  • It is based on the concept of routing, where URLs are mapped to specific controller actions.

In summary, Web Forms is more suitable for rapid development of complex UIs, while MVC provides more control and flexibility over the application's architecture and design.

Follow-up 2

What is the role of ViewState in ASP.NET?

ViewState is a feature in ASP.NET that allows the state of controls on a web page to be automatically preserved between postbacks. It is used to store the values of controls and other page-specific data.

When a page is rendered, the values of controls are stored in a hidden field called __VIEWSTATE. When the page is posted back to the server, the values are retrieved from the __VIEWSTATE field and applied to the controls.

ViewState helps maintain the state of controls and allows for a more interactive and user-friendly web application experience. However, it can also increase the size of the page and affect performance, especially when dealing with large amounts of data. It is important to use ViewState judiciously and disable it for controls or pages where it is not necessary.

Follow-up 3

What is the difference between Session and Cookies in ASP.NET?

Session and Cookies are both mechanisms in ASP.NET for maintaining state between requests, but they have some key differences.

Session:

  • Session is a server-side mechanism for storing user-specific data.
  • It uses a unique session ID to associate data with a specific user.
  • Session data is stored on the server and can be accessed by multiple pages in the same session.
  • Session data is cleared when the session expires or is explicitly cleared.

Cookies:

  • Cookies are small text files that are stored on the client-side (user's browser).
  • They can be used to store user-specific data or preferences.
  • Cookies are sent to the server with each request, allowing the server to retrieve the stored data.
  • Cookies can have an expiration date, after which they are automatically deleted.

In summary, Session is more secure as the data is stored on the server, while Cookies are stored on the client-side. Cookies are also more flexible as they can be used for non-user-specific data and have an expiration date.

Follow-up 4

How does ASP.NET handle error management?

ASP.NET provides several mechanisms for handling errors and exceptions in web applications.

  1. Custom Error Pages: ASP.NET allows you to define custom error pages that are displayed when an unhandled exception occurs. These pages can provide user-friendly error messages and additional information for troubleshooting.

  2. Global Error Handling: ASP.NET provides a global error handling mechanism through the Application_Error event in the Global.asax file. This event is triggered whenever an unhandled exception occurs and allows you to log the error, redirect the user to a custom error page, or perform other error handling tasks.

  3. Try-Catch Blocks: Developers can use try-catch blocks to catch and handle exceptions at the code level. This allows for more granular error handling and the ability to recover from specific exceptions.

  4. Logging: ASP.NET supports various logging frameworks, such as log4net and NLog, which can be used to log errors and exceptions for debugging and troubleshooting purposes.

By using these error management techniques, developers can handle errors gracefully and provide a better user experience in their ASP.NET applications.

2. Can you explain the ASP.NET page life cycle?

It is important to distinguish between the classic ASP.NET Web Forms page lifecycle and the modern ASP.NET Core request pipeline, as interviews may reference either.

Classic ASP.NET Web Forms lifecycle (legacy, .NET Framework only):

The page lifecycle is the sequence of events that occur when a Web Forms page is processed:

  1. Page Request – IIS receives the request; ASP.NET checks whether to serve cached output or process the page.
  2. StartRequest and Response objects are set; IsPostBack is determined.
  3. InitializationPage.Init fires; controls are initialized but ViewState is not yet loaded.
  4. LoadPage.Load fires; ViewState and postback data are restored.
  5. Validation – Validators run (Page.Validate()).
  6. Postback Event Handling – Control events (e.g., Button.Click) are raised and handled.
  7. RenderingPage.Render generates HTML; ViewState is serialized into the page.
  8. UnloadPage.Unload fires; cleanup occurs (closing connections, etc.).

ASP.NET Core request pipeline (modern):

ASP.NET Core does not have a Web Forms-style page lifecycle. Instead, it uses a middleware pipeline configured in Program.cs. Each request flows through a series of middleware components in order:

app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseAuthentication();
app.UseAuthorization();
app.MapControllers(); // or app.MapRazorPages() / minimal API endpoints

Middleware can short-circuit the pipeline (e.g., return a 401) or pass the request to the next component via next(). Razor Pages and MVC have their own action execution pipeline (filters, model binding, action execution, result execution) but there is no concept of ViewState or postback.

↑ Back to top

Follow-up 1

What is the difference between the Load and PreRender events in the ASP.NET page life cycle?

The Load event occurs after the Init event and is used to load the state information from the previous request and perform any necessary data binding. It is commonly used to populate controls with data.

The PreRender event occurs after the Load event and is used to perform any final modifications to the page before it is rendered. It is commonly used to update the UI based on user input or perform any necessary cleanup tasks. The PreRender event is the last event in the page life cycle before the page is rendered.

Follow-up 2

What is the role of the Init event in the ASP.NET page life cycle?

The Init event is the first event in the ASP.NET page life cycle. It occurs after the page and controls have been initialized, but before the page is loaded. The Init event is commonly used to perform initialization tasks, such as setting initial values for controls or retrieving data from a database. It is important to note that the Init event is raised for each control on the page before the Load event is raised.

Follow-up 3

How can we handle postback events in the ASP.NET page life cycle?

Postback events, such as button clicks, can be handled in the ASP.NET page life cycle by implementing event handlers for the corresponding events. When a postback event occurs, the ASP.NET framework raises the corresponding event and executes the event handler code.

To handle a postback event, you can add an event handler method to the control's event. For example, to handle a button click event, you can add a method to the button's Click event.

Here is an example of handling a button click event in the ASP.NET page life cycle:

protected void Button_Click(object sender, EventArgs e)
{
    // Event handler code
}

3. What is the difference between ASP.NET MVC and ASP.NET Web API?

In modern .NET, this distinction has largely collapsed. ASP.NET Core provides a unified framework where MVC controllers and API controllers share the same infrastructure.

Classic distinction (legacy .NET Framework):

  • ASP.NET MVC was used to build web pages that return HTML views using the Model-View-Controller pattern.
  • ASP.NET Web API was a separate framework for building HTTP services returning JSON or XML, consumed by browsers, mobile apps, or other services.

Modern ASP.NET Core (the correct answer for .NET 8/9):

ASP.NET Core unifies both under one framework:

  • MVC Controllers (Controller base class): Return HTML views via Razor templates, or can return IActionResult including JSON.
  • API Controllers (ControllerBase + [ApiController]): Optimized for building RESTful APIs. They return data (JSON by default), include automatic model validation, and use attribute routing.
  • Minimal APIs: Lightweight alternative to controllers for HTTP endpoints, using app.MapGet(), app.MapPost(), etc. Ideal for microservices.
  • Razor Pages: Page-centric model for web UI, an alternative to MVC views for page-focused scenarios.

The key remaining distinction: use [ApiController] / Minimal APIs when building data-serving APIs (no views), and MVC / Razor Pages when building server-rendered web UI.

↑ Back to top

Follow-up 1

Can you explain how routing works in ASP.NET MVC?

In ASP.NET MVC, routing is the process of mapping incoming URLs to controller actions. The routing engine examines the URL of each incoming request and tries to match it with a route defined in the application's route table. Each route consists of a URL pattern and a corresponding controller and action. When a match is found, the routing engine invokes the specified controller action to handle the request. Routing in ASP.NET MVC is highly customizable and allows for the use of route parameters, constraints, and default values.

Follow-up 2

What is the role of filters in ASP.NET MVC?

Filters in ASP.NET MVC are used to add additional behavior to controller actions or to the entire request/response pipeline. They can be used to perform tasks such as authentication, authorization, logging, exception handling, and caching. There are several types of filters in ASP.NET MVC, including action filters, result filters, authorization filters, and exception filters. Filters can be applied globally to all actions in the application, to specific controllers or actions, or even dynamically at runtime.

Follow-up 3

How does model binding work in ASP.NET Web API?

Model binding in ASP.NET Web API is the process of mapping incoming HTTP request data to the parameters of a Web API controller action. When a request is received, the Web API framework automatically binds the data from the request to the parameters of the action method based on the parameter names and the data in the request. The framework supports various types of model binding, including binding from the query string, form data, route data, and even from the request body in the case of complex types. Model binding in Web API is highly flexible and can be customized using attributes and configuration settings.

4. What is the role of the Global.asax file in ASP.NET?

Global.asax is a legacy concept from classic ASP.NET (Web Forms / MVC on .NET Framework) and does not exist in ASP.NET Core.

In classic ASP.NET:

Global.asax (also called the Application file) was an optional file that contained event handlers for application-level events:

  • Application_Start – Runs once when the application starts; used for routing registration, bundle configuration, etc.
  • Application_End – Runs when the application shuts down.
  • Application_BeginRequest / Application_EndRequest – Fire on every request.
  • Session_Start / Session_End – Fire when a user session starts or ends.
  • Application_Error – Global error handler.

In ASP.NET Core (modern replacement):

Global.asax is replaced by Program.cs (and formerly Startup.cs, now merged into Program.cs in .NET 6+):

  • Application startup: Configuration, service registration (builder.Services.Add*()), and middleware pipeline setup (app.Use*()) all happen in Program.cs.
  • Request pipeline events: Middleware handles what Application_BeginRequest used to do.
  • Error handling: app.UseExceptionHandler() or app.UseDeveloperExceptionPage() replaces Application_Error.
  • Hosted services (IHostedService / BackgroundService): Handle startup/shutdown lifecycle tasks.
// Program.cs in ASP.NET Core — replaces Global.asax
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllers();

var app = builder.Build();
app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();
app.Run();
↑ Back to top

Follow-up 1

What are the main events in the Global.asax file?

The main events in the Global.asax file are:

  • Application_Start: This event is fired when the application starts. It is typically used to perform application-level initialization tasks, such as registering routes, configuring logging, or setting up dependency injection containers.

  • Session_Start: This event is fired when a new session starts. It is typically used to perform session-level initialization tasks, such as initializing session variables or setting session-specific configuration.

  • Application_Error: This event is fired when an unhandled exception occurs in the application. It allows you to handle and log the error, and optionally redirect the user to a custom error page.

  • Application_End: This event is fired when the application ends. It is typically used to perform cleanup tasks, such as releasing resources or closing database connections.

Follow-up 2

How can we handle application level errors in the Global.asax file?

To handle application-level errors in the Global.asax file, you can use the Application_Error event. This event is fired when an unhandled exception occurs in the application. You can write code in the event handler to handle the error, log it, and optionally redirect the user to a custom error page.

Here is an example of how to handle application-level errors in the Global.asax file:

protected void Application_Error(object sender, EventArgs e)
{
    Exception exception = Server.GetLastError();
    // Handle the error
    // Log the error
    // Redirect the user to a custom error page
    Server.ClearError();
    Response.Redirect("~/Error.aspx");
}

Follow-up 3

Can you explain the difference between Application_Start and Session_Start in the Global.asax file?

Yes, Application_Start and Session_Start are two different events in the Global.asax file.

  • Application_Start: This event is fired when the application starts. It is used to perform application-level initialization tasks that need to be done only once, such as registering routes, configuring logging, or setting up dependency injection containers. This event is not specific to any user session.

  • Session_Start: This event is fired when a new session starts. It is used to perform session-level initialization tasks that need to be done for each user session, such as initializing session variables or setting session-specific configuration.

In summary, Application_Start is fired once when the application starts, while Session_Start is fired for each new user session.

5. Can you explain how authentication and authorization work in ASP.NET?

Authentication verifies who the user is. Authorization determines what they are allowed to do. ASP.NET Core treats these as separate, composable middleware steps.

Authentication in ASP.NET Core:

Authentication is configured as a middleware service:

builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
    .AddJwtBearer(options => { /* configure */ });
// or
    .AddCookie()
    .AddGoogle(...)
    .AddOpenIdConnect(...)

app.UseAuthentication() must appear before app.UseAuthorization() in the pipeline. Common schemes:

  • JWT Bearer tokens – Standard for APIs; client sends Authorization: Bearer.
  • Cookie authentication – Common for server-rendered web apps.
  • OAuth2 / OpenID Connect – For delegating to external identity providers (Google, Microsoft, Auth0).
  • ASP.NET Core Identity – Complete membership system with user/role management, password hashing, email confirmation, etc.

Authorization in ASP.NET Core:

Authorization supports multiple models:

  • Role-based: [Authorize(Roles = "Admin")]
  • Policy-based: Flexible, composable rules:
builder.Services.AddAuthorization(options =>
{
    options.AddPolicy("MinAge18", policy =>
        policy.RequireClaim("age", "18"));
});
  • Resource-based: Authorization decisions depend on the resource being accessed, handled via IAuthorizationService.
  • Claims-based: Inspect claims on the ClaimsPrincipal.

For production applications, pairing ASP.NET Core Identity with an identity provider like Duende IdentityServer, Keycloak, or Microsoft Entra ID (Azure AD) is recommended for OAuth2/OIDC flows.

↑ Back to top

Follow-up 1

What is the difference between Windows authentication and Forms authentication in ASP.NET?

Windows authentication and Forms authentication are two different authentication methods in ASP.NET.

Windows authentication relies on the Windows operating system to authenticate users. It uses the user's Windows credentials to verify their identity. This method is commonly used in intranet scenarios where the application and the users are part of the same Windows domain.

Forms authentication, on the other hand, is a custom authentication method provided by ASP.NET. It uses a login form to collect user credentials and verifies them against a user store, such as a database. This method is commonly used in internet scenarios where the application and the users are not part of the same Windows domain.

Follow-up 2

How can we implement role-based authorization in ASP.NET?

Role-based authorization in ASP.NET allows you to restrict access to certain resources or actions based on the roles assigned to users.

To implement role-based authorization in ASP.NET, you can follow these steps:

  1. Define roles: Create roles that represent different levels of access in your application.

  2. Assign roles to users: Associate roles with users either manually or programmatically.

  3. Authorize actions or resources: Use the [Authorize] attribute or the Authorize attribute with roles parameter to restrict access to specific actions or resources based on the roles assigned to users.

For example, you can use the [Authorize(Roles = "Admin")] attribute to restrict access to an action or a controller to users with the "Admin" role.

Follow-up 3

What is the role of the [Authorize] attribute in ASP.NET?

The [Authorize] attribute in ASP.NET is used to apply authorization rules to actions or controllers.

When the [Authorize] attribute is applied to an action or a controller, it restricts access to that action or controller to authenticated users only. If an unauthenticated user tries to access the action or controller, they will be redirected to the login page.

The [Authorize] attribute can also be used with additional parameters to specify role-based authorization. For example, you can use the [Authorize(Roles = "Admin")] attribute to restrict access to an action or a controller to users with the "Admin" role.

Live mock interview

Mock interview: Exploring ASP.NET

Intermediate ~5 min Your own free AI key

Your voice and your AI key never touch our servers; the key stays in this browser and is sent only to Google. Only your round scores are saved to track progress.