ASP.NET is a web application framework designed and developed by Microsoft. ASP.NET is open source and a subset of the .NET Framework and successor of the classic ASP(Active Server Pages). With version 1.0 of the .NET Framework, it was first released in January 2002. So a question comes to mind that which technology we were using before the year 2002 for developing web applications and services? Answer is Classic ASP. So before .NET and ASP.NET there was Classic ASP.

ASP.NET is built on the CLR(Common Language Runtime) which allows the programmers to execute its code using any .NET language(C#, VB etc.). It is specially designed to work with HTTP and for web developers to create dynamic web pages, web applications, web sites, and web services as it provides a good integration of HTML, CSS, and JavaScript.

 

.NET Framework is used to create a variety of applications and services like Console, Web, and Windows, etc. But ASP.NET is only used to create web applications and web services. That’s why we termed ASP.NET as a subset of the .NET Framework.

These questions cover a range of topics related to ASP.NET, including its various components, programming languages, security measures, database access, and performance optimization. Interviewers may tailor the questions based on the specific requirements of the job and the candidate’s level of expertise.

ASP.Net Interview Questions

An ASP web configuration file is a file named “web.config” used in ASP.NET web applications to define configuration settings. It’s an XML file that contains information such as:

  • Connection strings for databases
  • Application settings and keys
  • Authorization and authentication rules
  • URL rewriting rules
  • Custom error pages
  • NET modules and handlers

The web.config file is located in the root directory of an ASP.NET application and affects the entire application, unless overridden by a lower-level configuration file.

The Asp.Net life cycle is the process that the Asp.Net framework goes through to handle a request for a web page and return the response to the client. The life cycle consists of the following events:

  1. Request Start :
  • A new request is received and the Netengine starts processing it.
  1. Routing :
  • The request URL is analyzed to determine which page or resource should handle the request.
  1. Execution of Application Start:
  • The Application_Start event is fired, which is only fired once per application and is used to initialize global objects or perform other application-level tasks.
  1. Execution of Request Start :
  • The Request_Start event is fired and the request context is created.
  1. Module Initialization :
  • The Netmodules and handlers associated with the request are initialized.
  1. Execution of AcquireRequestState :
  • The AcquireRequestState event is fired and the state data for the request is retrieved.
  1. Execution of PreRequestHandlerExecute :
  • The PreRequestHandlerExecute event is fired and the appropriate page handler is determined.
  1. Execution of Page Execution :
  • The page handler executes the logic for the requested page.
  1. Execution of PostRequestHandlerExecute :
  • The PostRequestHandlerExecute event is fired and the response is sent to the client.
  1. Execution of ReleaseRequestState :
  • The ReleaseRequestState event is fired and the state data is stored for the next request.
  1. Execution of End Request :
  • The EndRequest event is fired and the request context is destroyed.
  1. Request End :
  • The Netengine has finished processing the request and is ready to handle the next request.

ASP (Active Server Pages) and Asp.Net are both Microsoft technologies used for creating web applications, but they have some key differences:

  1. Language :
  • ASPused VBScript or JScript as the scripting language, while Net supports a wider range of languages, including C# and VB.NET.
  1. Architecture :
  • ASPis based on a scripting model, which means that all the code is executed on the server and the HTML is sent to the client. Net, on the other hand, uses a compiled, event-driven model that allows for better separation of code and HTML.
  1. Performance :
  • Netis generally faster and more scalable than ASP, as the code is compiled and optimized before it is executed.
  1. Security :
  • Netprovides a more secure environment than ASP, with built-in features for protecting against common security threats, such as SQL injection and cross-site scripting.
  1. Debugging and Error Handling :
  • Netprovides improved debugging and error handling capabilities, with built-in support for tracing, logging, and exception handling.
  1. Development Environment :
  • Netcan be developed using Microsoft Visual Studio, a comprehensive development environment with many tools and features for designing, debugging, and testing web applications.

In conclusion, while ASP was a popular technology for creating web applications in the past, Asp.Net offers many advantages over ASP and is the preferred choice for modern web development.



The architecture of ASP (Active Server Pages) is based on a scripting model, which consists of the following components:

  1. Web Server :
  • The web server, such as Internet Information Services (IIS), receives a request from a client and passes it on to the ASP
  1. ASP Engine :
  • The ASPengine processes the ASP script and generates HTML or other output that is sent back to the client.
  1. Scripting Language :
  • ASPsupports VBScript or JScript as the scripting language, which is used to write the code that generates the HTML or other output.
  1. Components :
  • ASPsupports the use of components, such as ActiveX controls or COM objects, which can be called from the ASP script to perform specific tasks, such as connecting to a database or generating dynamic content.
  1. Data Access :
  • ASPprovides a simple API for accessing data, such as the ADO (ActiveX Data Objects) API, which can be used to retrieve and manipulate data from databases or other data sources.

In this architecture, the client sends a request to the web server, which passes it on to the ASP engine. The ASP engine processes the ASP script, generates the HTML or other output, and returns it to the client. The script can make use of components and data access APIs to generate dynamic content based on data from databases or other sources.

Asp.Net is a web application framework developed by Microsoft for creating dynamic and interactive web applications. It is part of the .NET framework and is built on the Common Language Runtime (CLR), which provides a managed, secure, and scalable environment for web development.

Some key features of Asp.Net include:

  1. Language Support :
  • Netsupports multiple programming languages, including C# and VB.NET, allowing developers to choose the language they are most comfortable with.
  1. Model-View-Controller (MVC) Architecture :
  • NetMVC is a design pattern that separates an application into three main components: the model (data), the view (presentation), and the controller (logic).
  1. Security :
  • Netprovides built-in security features, such as authentication and authorization, to help protect against common security threats, such as SQL injection and cross-site scripting.
  1. Performance :
  • Netis optimized for performance and scalability, with features such as caching and output compression to improve page load times.
  1. Development Environment :
  • Netcan be developed using Microsoft Visual Studio, a comprehensive development environment with many tools and features for designing, debugging, and testing web applications.

In conclusion, Asp.Net is a powerful and flexible framework for creating dynamic web applications. It provides a managed, secure, and scalable environment for web development and supports multiple programming languages and design patterns.

  • Design” in the context of ASP(Active Server Pages) refers to the process of creating the visual and functional elements of a web page or web application. This includes defining the layout, appearance, and functionality of the page, as well as deciding on the content and features that will be included.
  • In ASP, the design of a web page or application is typically done using HTML, CSS, and JavaScript, along with the scripting language (such as VBScript or JScript) used in the ASP The design of an ASPapplication can be influenced by factors such as the target audience, the purpose of the application, and the platform and devices that the application will be run on.
  • The goal of the design process is to create a user-friendly and visually appealing interface that effectively communicates the intended message or content, while also providing the necessary functionality to meet the requirements of the application.
  • In summary, design in the context of ASPrefers to the creation of the visual and functional elements of a web page or application, and is a critical component in creating a successful and effective ASP
  • The main difference between the whileand do while loops in ASP (Active Server Pages) is the order in which the loop conditions are evaluated and the way in which the loop body is executed.
  • The whileloop in ASP evaluates the loop condition before entering the loop body. If the condition is false, the loop body is not executed and the program continues with the next statement after the loop. If the condition is true, the loop body is executed, and the condition is re-evaluated after each iteration. The loop continues to execute as long as the condition remains true.
  • The do whileloop, on the other hand, first executes the loop body and then evaluates the loop condition. The loop body is always executed at least once, regardless of the value of the condition. If the condition is false, the loop terminates and the program continues with the next statement after the loop. If the condition is true, the loop continues to execute, re-evaluating the condition after each iteration.
  • In summary, the main difference between whileand do while loops in ASP is the order in which the loop conditions are evaluated and the way in which the loop body is executed. The while loop evaluates the condition before entering the loop body, while the do while loop executes the loop body first and then evaluates the condition.

Asp.Net Web API is a framework for building RESTful (Representational State Transfer) web services on the Asp.Net platform. It is designed to provide a simple, lightweight, and easy-to-use platform for creating HTTP-based APIs that can be consumed by a wide variety of clients, including web browsers, mobile devices, and desktop applications.

Some key features of Asp.Net Web API include:

  1. HTTP Support :
  • NET Web APIis built on top of HTTP, providing support for common HTTP methods such as GET, POST, PUT, and DELETE, making it easy to interact with the API using standard HTTP requests.
  1. Routing :
  • NET Web APIprovides a flexible and powerful routing mechanism that allows developers to define the structure of their API endpoints and map incoming requests to the appropriate action.
  1. Content Negotiation :
  • NET Web APIprovides support for content negotiation, which allows the client to specify the format of the response it wants to receive (e.g. JSON, XML, etc.).
  1. Model Binding :
  • NET Web APIprovides support for model binding, which makes it easy to convert incoming HTTP requests into strongly-typed objects.
  1. Exception Handling :
  • NET Web APIprovides a flexible and extensible exception handling mechanism, allowing developers to catch and handle errors in a consistent manner.
  1. Security :
  • NET Web APIprovides built-in support for authentication and authorization, making it easy to secure access to the API.

In conclusion, ASP.NET Web API is a flexible and powerful framework for building RESTful web services. Its support for HTTP, routing, content negotiation, model binding, exception handling, and security makes it easy to create and consume APIs that can be consumed by a wide variety of clients.



  • Sessionin ASP (Active Server Pages) refers to a mechanism for storing and maintaining state information for individual users of a web application. Session state is a collection of variables that are stored on the server and can be accessed by the server-side scripts of an ASP application to persist information about a user’s Session.
  • When a user visits an ASP application, a new sessionis created for that user on the server. The server assigns a unique session ID to the user, which is then passed between the server and the client in a cookie or as a part of the URL. This allows the server to keep track of the user’s session and access the session state information.
  • Sessionstate information is stored on the server in memory and can be used to persist data across multiple requests from the same user. This makes it useful for maintaining information such as user authentication and shopping cart information, as well as any other data that needs to be persisted across multiple requests.
  • In ASP, sessionstate is managed using the Session object, which provides a dictionary-like interface for accessing and manipulating the session state information.
  • In conclusion, sessionin ASP refers to a mechanism for storing and maintaining state information for individual users of a web application, and is managed using the Session The session state information is stored on the server in memory and can be used to persist data across multiple requests from the same user.

Here is an example of how you can create a basic ASP.NET Web API using C#:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;

namespace MyWebApi.Controllers
{
public class ValuesController : ApiController
{
static List<string> values = new List<string>()
{
"value1", "value2", "value3"
};

// GET api/values
public IEnumerable<string> Get()
{
return values;
}

// GET api/values/5
public string Get(int id)
{
return values[id];
}

// POST api/values
public void Post([FromBody] string value)
{
values.Add(value);
}

// PUT api/values/5
public void Put(int id, [FromBody] string value)
{
values[id] = value;
}

// DELETE api/values/5
public void Delete(int id)
{
values.RemoveAt(id);
}
}
}

This example creates a basic Web API with the following endpoints:

  1. GET api/values :
  • Returns an array of all values stored in the values
  1. GET api/values/{id} :
  • Returns the value at the specified index in the values
  1. POST api/values :
  • Adds a new value to the values
  1. PUT api/values/{id} :
  • Updates the value at the specified index in the values
  1. DELETE api/values/{id} :
  • Deletes the value at the specified index in the values

This example uses the ApiController class to create a RESTful API and the Http methods (GET, POST, PUT, DELETE) to handle the different types of requests. The FromBody attribute is used to specify that the value in the body of the request should be bound to the value parameter. The example uses a static list to store the values, but in a real-world scenario, you would typically store the values in a database.

In ASP.NET, a statement is a line of code that performs a specific action or operation. Statements are used to define the logic of an application, and they can be used to manipulate data, control program flow, and interact with the user interface.

Some examples of statements in ASP.NET might include:

  • Variable declarations, such as “int x = 10;” which declares a variable called “x” and initializes it with the value of 10.
  • Method calls, such as “Console.WriteLine(“Hello, World!”);” which calls the WriteLine method of the Console class to output the string “Hello, World!” to the console.
  • Control flow statements, such as “if (x > 0) { … }” which checks if the value of the variable “x” is greater than 0, and executes the code within the curly braces if the condition is true.

In ASP.NET, statements are used to build up the logic of an application, and they can be combined together to create more complex functionality.

In ASP (Active Server Pages), statement management types are used to control the flow of execution of statements. The following are the most common statement management types:

  1. Conditional statements :
  • These statements allow you to execute a certain block of code based on certain conditions. The most commonly used conditional statements are ifand 
  1. Looping statements :
  • These statements allow you to execute a block of code repeatedly while a certain condition is true. The most commonly used looping statements are for, while, and do while.
  1. Exception handling statements :
  • These statements allow you to handle errors and exceptions in your code. The most commonly used exception handling statement is the ..catchblock.
  1. Jump statements :
  • These statements allow you to jump to a different point in your code. The most commonly used jump statements are breakand 
  1. Subroutine and function calls :
  • These statements allow you to call and execute a subroutine or function.

In conclusion, statement management types in ASP are used to control the flow of execution of statements. They include conditional statements, looping statements, exception handling statements, jump statements, and subroutine and function calls.



CRUD (Create, Read, Update, and Delete) operations are the basic operations that can be performed on a database. In ASP.NET and C#, these operations can be performed using various techniques and technologies, including:

  1. ADO.NET :
  • The traditional way to perform CRUDoperations in ASP.NET is by using ADO.NET, which provides a set of classes for accessing and manipulating databases.
  1. LINQ :
  • LINQ (Language Integrated Query) is a technology introduced in .NET 3.5 that allows you to perform CRUDoperations using a simple and expressive syntax.
  1. Entity Framework :
  • Entity Framework is an Object Relational Mapping (ORM) tool that provides an abstraction layer over a database. It makes it easy to perform CRUDoperations and eliminates the need for writing raw SQL.

Here is an example of how to perform CRUD operations using ADO.NET:

using System;
using System.Data;
using System.Data.SqlClient;

namespace AdoNetExample
{
class Program
{
static void Main(string[] args)
{
// Connect to the database
using (SqlConnection connection = new SqlConnection("Data Source=(local);Initial Catalog=TestDB;Integrated Security=True"))
{
connection.Open();

// Create
using (SqlCommand cmd = new SqlCommand("INSERT INTO Customers (Name, Email) VALUES (@Name, @Email)", connection))
{
cmd.Parameters.AddWithValue("@Name", "John Doe");
cmd.Parameters.AddWithValue("@Email", "[email protected]");
cmd.ExecuteNonQuery();
}

// Read
using (SqlCommand cmd = new SqlCommand("SELECT * FROM Customers", connection))
{
using (SqlDataReader reader = cmd.ExecuteReader())
{
while (reader.Read())
{
Console.WriteLine("{0} - {1}", reader["Name"], reader["Email"]);
}
}
}

// Update
using (SqlCommand cmd = new SqlCommand("UPDATE Customers SET Name=@Name WHERE Email=@Email", connection))
{
cmd.Parameters.AddWithValue("@Name", "Jane Doe");
cmd.Parameters.AddWithValue("@Email", "[email protected]");
cmd.ExecuteNonQuery();
}

// Delete
using (SqlCommand cmd = new SqlCommand("DELETE FROM Customers WHERE Email=@Email", connection))
{
cmd.Parameters.AddWithValue("@Email", "[email protected]");
cmd.ExecuteNonQuery();
}
}
}
}
}

In conclusion, CRUD operations can be performed in ASP.NET and C# using various technologies and techniques, including ADO.NET, LINQ, and Entity Framework. The choice of technology depends on the requirements and constraints of your project.



In ASP.NET, configuration files are used to store configuration settings for an application. There are several types of configuration files used in ASP.NET, including:

  1. Web.config :
  • This is the main configurationfile for an ASP.NET web application. It contains settings for the application, such as connection strings, security settings, and custom configuration
  1. Machine.config :
  • This is the configurationfile for the .NET runtime, and contains settings that apply to all ASP.NET applications on a server.
  1. App.config :
  • This is the configurationfile for a .NET desktop application. It is similar to the web.config file, but is used for desktop applications instead of web applications.
  1. Global.asax :
  • This file contains application-level events and settings, such as handling application start and end events, and registering HTTP modules.

The configuration files in ASP.NET use XML syntax, and can be edited manually or programmatically. Configuration files are used to store a wide range of settings, including security settings, database connection strings, custom configuration sections, and more.

Here’s an example of how you can use delegates in C# to display numbers in a triangular form:

using System;

namespace TriangularFormExample
{
delegate void DisplayDelegate(int number);

class Program
{
static void Main(string[] args)
{
DisplayDelegate displayDelegate = DisplayTriangularForm;
displayDelegate(5);
}

static void DisplayTriangularForm(int number)
{
for (int i = 1; i <= number; i++)
{
for (int j = 1; j <= i; j++)
{
Console.Write(j + " ");
}
Console.WriteLine();
}
}
}
}

This program defines a delegate named “DisplayDelegate” that takes an integer as a parameter. The Main method creates an instance of the delegate and assigns the “DisplayTriangularForm” method to it. The “DisplayTriangularForm” method uses nested loops to display the numbers in a triangular form. When the program is run, the output will be:

1
1 2
1 2 3
1 2 3 4
1 2 3 4 5

In ASP.NET, there are four types of state management:

  1. View State :
  • It is a client-side statemanagement technique that stores the values of controls on a page between postbacks.
  1. Session State :
  • It is a server-side statemanagement technique that stores data for a user session.
  1. Application State :
  • It is a global statemanagement technique that stores data for all users of an application.
  1. Cookies :
  • It is a client-side statemanagement technique that stores data on the user’s computer.

These state management techniques allow you to store and retrieve data between multiple page requests, which is essential for building dynamic and interactive web applications.

In ASP.NET MVC, authorization can be performed in the following ways:

  1. Role-based authorization :
  • You can use the [Authorize] attribute to restrict access to a specific action or controller to users with a specific role.
  1. Claims-based authorization :
  • You can use claims-based authorizationto grant or deny access based on a user’s claims, such as their name, email address, or other information.
  1. Custom authorization :
  • You can create a custom authorizationfilter to implement custom logic for authorization.

To perform authorization in ASP.NET MVC, you need to follow these steps:

  • Create an ASP.NET MVC application.
  • Add the [Authorize] attribute to the action or controller that you want to restrict access to.
  • Configure the authentication and authorizationsettings in the web.config file.
  • Implement the authorizationlogic in the custom authorization filter, if necessary.
  • Test the authorizationby logging in as different users with different roles or claims and attempting to access the restricted action or controller.
  • In ASP.NET, a partialclass is a class that is split into multiple files, but still functions as a single class. Partial classes are useful when you want to separate the code of a single class into multiple files, for example, to organize the code more effectively or to allow multiple developers to work on the same class at the same time.

partial class is defined using the “partial” keyword in C#. For example:

public partial class MyClass
{
// code for first part of the class
}

And in another file:

public partial class MyClass
{
// code for second part of the class
}
  • When the application is compiled, the two parts of the class are combined into a single class that can be used in the same way as a normal class. Partialclasses are commonly used in ASP.NET for generating code, such as code for model classes or for view classes.

In ASP.NET, the .asmx file and the .asmx.cs file are related as follows:

  • The .asmxfile is an XML-based file that defines a web service in ASP.NET. It contains information about the web service, such as its URL and the methods that it exposes.
  • The .asmx.csfile is a C# code-behind file that contains the code for the web service. It implements the methods defined in the .asmx file, and provides the actual functionality for the web service.

To indicate that the .asmx.cs file is a part of the .asmx file, the .asmx.cs file typically has a partial class with the same name as the .asmx file. For example, if the .asmx file is named MyWebService.asmx, the .asmx.cs file would be named MyWebService.asmx.cs and contain a partial class named MyWebService. This way, the two files can be combined at compile time to form a single class that implements the web service.

To connect a Web API in ASP.NET, you need to follow these steps:

  • Create an ASP.NET Web APIproject in Visual Studio.
  • Define the controllers and actions for your API. You can use the built-in controllers in ASP.NET Web API, or create your own custom controllers.
  • Test the API by running the application in the development environment. You can use a tool like Postman to send HTTP requests to the API and receive the responses.
  • Publish the API to a web server or hosting platform.
  • To connect to the API from a client application, you can use the HttpClientclass in .NET to send HTTP requests to the API and receive the responses.

Here’s an example of how to use HttpClient to connect to a Web API:

using System;
using System.Net.Http;
using System.Threading.Tasks;

namespace ConsoleApp
{
class Program
{
static async Task Main(string[] args)
{
using (var client = new HttpClient())
{
client.BaseAddress = new Uri("https://api.example.com/");

var response = await client.GetAsync("api/values");

if (response.IsSuccessStatusCode)
{
var values = await response.Content.ReadAsAsync<string[]>();
Console.WriteLine("Values: " + string.Join(", ", values));
}
else
{
Console.WriteLine("Error: " + response.StatusCode);
}
}
}
}
}

This code creates an instance of HttpClient, sets its BaseAddress property to the base URL of the API, and then sends a GET request to the /api/values endpoint of the API. If the request is successful, the response is read as an array of strings and displayed on the console. If the request fails, the error status code is displayed on the console.



  • code-behindfile in ASP.NET is a file that contains the code that is associated with a particular ASP.NET web page, user control, or master page. The code-behind file is typically written in a .NET programming language, such as C# or VB.NET, and is separated from the markup in the ASP.NET page.
  • The code-behindfile is created by adding a code-behind class to the ASP.NET project, and then linking the code-behind class to the ASP.NET page using the CodeFile attribute in the page’s directive. The code-behind file is compiled into a .NET assembly, along with the rest of the ASP.NET project, and is executed on the server when the ASP.NET page is requested.
  • Using a code-behindfile provides a clean separation between the presentation and logic in an ASP.NET application, and makes it easier to maintain and test the code. The code-behind file can contain event handlers, custom methods, and other code that is executed in response to user actions or other events in the ASP.NET page.

Here’s an example of a simple code-behind file in C#:

using System;

public partial class Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
// Initialize the page
}
}

protected void Button1_Click(object sender, EventArgs e)
{
// Handle the button click event
}
}
  • This code-behindfile defines a partial class named Default that is derived from the Web.UI.Page class. The class contains two event handlers: Page_Load and Button1_Click. The Page_Load event handler is executed when the ASP.NET page is loaded, and the Button1_Click event handler is executed when a button on the page is clicked.



  • A page theme in ASP.NET is a collection of style definitions and images that are applied to a set of pages in an ASP.NET web application. Themes allow you to define a consistent look and feel for your web pages, making it easier to maintain and update the visual appearance of your site.
  • A theme is defined in a theme folder, which contains the style sheets, images, and other resources used by the theme. The theme folder is usually located in the App_Themesfolder of your ASP.NET web application.
  • To apply a theme to a page in ASP.NET, you can use the Themeproperty. For example, you could set the theme for a page in the Page directive, like this:
<%@ Page Theme = "MyTheme" %>

You can also set the theme for an entire web site in the Web.config file, using the pages section:

< configuration >
< system.web >
< pages theme = "MyTheme" >
...
</ pages >
</ system.web >
</ configuration >
<%@ Page Theme = "MyTheme" %>
  • In this example, the theme named “MyTheme” is applied to all pages in the web site.
  • By using themes in ASP.NET, you can easily change the look and feel of your web site by swapping out one theme for another, without having to make changes to the underlying pages or code.

 

Categorized in: