List of the most popular frequently asked ASP.Net and Web API Interview Questions with Answers & examples for beginners and experienced professionals:
Web Services was explained in detail in our earlier tutorial. We will focus on some of the most commonly asked Web API interview questions in this tutorial.
These ASP.Net And Web API Interview questions are in trend and are being asked during the technical rounds of the hiring process. The questions include both subjective and objective.
The level of difficulty is mixed and is appropriate for both beginners as well as experienced professionals.
=> Check Out The Free API Testing Guide Here
35 Best ASP.Net And Web API Interview Questions And Answers
Enlisted below are the most popular ASP.Net And Web API Interview Questions that would help you in the interview preparation process.
Q #1) What is ASP.Net?
Answer: ASP stands for Active Server Pages. Microsoft came up with a framework (ASP.Net) which was the updated version of legacy ASP. The library files and the ASP engine do not require to be modified while installing the framework.
This facilitated IIS (Internet Information Server) to keep both legacy ASP and ASP.Net scripts on the same system. IIS is nothing but the server provided by Microsoft that is used to provide Internet-based services to any ASP.Net or web applications. Any web page script is executed by IIS.
Q #2) What do you mean by Caching in ASP.Net?
Answer: Suppose you are visiting Google quite often and when you open a new tab on your browser (say Chrome), this web page will be there in the “most frequently used” section.
This means that google.com has been cached on your machine and it will be opened in much less time compared to the other websites that were not accessed in recent times. This is an example of Caching.
Thus, Caching is a mechanism that keeps the frequently accessed files in the cache memory and accesses them from the cache itself rather than the actual address of the files or data.
Q #3) What are the Types of Caching?
Answer: There are three different types of caching as shown below:
- Page Caching
- Data Caching
- Fragment Caching
Q #4) What is a Page Life Cycle? What are the events in a Page Life Cycle?
Answer: During the execution of any ASP.Net page, the page undergoes a list of events (right before it’s inception (initialization) till the end (rendering)). The occurrence of these events in chronological order on a Page is known as the Page Life Cycle.
Below is the list of all the events that occur during a Page Life Cycle.
Q #5) What is ViewState? In which event of the page life cycle, is the ViewState available?
Answer: ViewState is a state management technique that allows storing user input data on a page at the PostBack event of a web page. ViewState is available after Init and before PageLoad event of the page life cycle.
Q #6) What is the Life-Span of the items in the ViewState?
Answer: The life span of the items in the ViewState depends on the life of the current page. They exist as long as the current page exists.
Q #7) What is the Parent Class of all the Web Server control?
Answer: The parent class of all Web Server control is “System.Web.UI.Control”.
Q #8) How do you store a value in ViewState and Retrieve them?
Answer: As we know, ViewState stores the value of the page and the user inputs on a Page.
Following is the example of how we store the value in ViewState and retrieve it.
ViewState[“emp”]=”Saket Saurav”; // Store the value in ViewState
string value=ViewState[“emp”].ToString(); //Retrieve information
Q #9) What is the Base Class from which Web Forms are inherited?
Answer: Page class is the base class for all the WebForms.
Q #10) Write a code for sending an email from ASP.Net Application.
Answer: Writing a code snippet is very common in both ASP.net as well as Selenium interviews. For Selenium, we have already discussed how to send an email.
Below are the explanation and the code for sending an email from the ASP.Net application.
In the below program, we are creating an object for MailMessage. Thereafter, we are specifying the sender and recipient email addresses. Then, we are specifying the subject line as Software Testing.
Later, we are drafting the body of the email which is then sent with the use of a Simple Mail Transfer Protocol through the localhost server.
Code With Comments
MailMessage mail = new MailMessage (); //creating an obj for MailMessage mail.From = “firstname.lastname@example.org"; //specifying the sender mail id mail.To = "email@example.com"; //specifying the recipient mail id mail.Subject = "Software Testing"; //specifying the subject mail.Body = "Hi, Sending an email"; //drafting the body of the email SmtpMail.SmtpServer = "localhost"; //sending through the localhost server SmtpMail.Send (mail); //passing the attribute “mail” in the Smtp.Send()
Q #11) What is the file through which you can customize your ASP.Net Application?
Answer: web.config is the file through which we can customize our application in ASP.Net such as applying new themes, resizing images or cropping images.
Q #12) What is Query String in ASP.Net?
Answer: Query String is a string (collection of characters) that is passed on any web browser as a part of the address or URL. This is often separated by a question mark (?).
The syntax of the query string is Request.QueryString(variable)[(index).count]
Q #13) What are the Differences between Code-Behind and Code Inline?
- Code Behind is the code written in a separate class file whereas Code Inline is the code written inside an ASP.Net Web Page.
- Code Behind has an extension .aspx.cs or .aspx.vb whereas Code Inline (as it is inside ASP.Net) has an extension .aspx only. Code Inline is written inside <script> tag along with the HTML.
- Code for all the web pages is compiled into a .dll file (Data Link Library File) which is kept free from the Inline Code.
Q #14) What are Directives in ASP.Net? List down all the Important Directives.
Answer: Directives are the instructions that are used to describe how .aspx pages will be processed by the framework. Different directives come with different options or attributes and easily provide class names, their descriptions or the files’ names of the code-behind class for any specific page.
It starts with <%@ and ends with %>.
The syntax is:
<%@[DirectiveType][Attributes or Options]%>
Q #15) What are SQL Notifications and SQL Invalidations?
Answer: SQL notifications are the notifications that trigger when there is any change in the data which is copied in the cache.
SQL invalidation is something (you can call it a parser) that invalidates promptly when it finds any change in the data that is in the database against the copied data in the cache.
Q #16) What are Session State Modes? List some of the important Session State Modes of ASP.net.
Answer: Session state is something in which the session object stores information about any particular user logged into the system. This session information can be the user id or password, details about the user’s last login, last activity and so on.
This session state comes up with different storage options. Again, each option is handled by the value in the session state mode.
Important Session State Modes
- State Server Mode: Stores session state in ASP.Net State Service. Session State does not hamper by the restart of the application in a particular region.
- InProc Mode: A default mode in which the session state is stored in memory on the Web Server.
- SQL Server Mode: Session State is stored in SQL Server Database. It is the same as State Server in preserving the session state even though the application restarts.
- Custom Mode: Session state is stored in a custom storage provider. It (Custom Storage Provider) can be configured by the user.
- Off Mode: This enables the offline mode. The Session State is disabled in this mode.
Q #17) What is the difference between Server.Transfer and Response.Redirect?
Answer: As we know, both Server.Transfer and Response.Redirect are used to facilitate the users to navigate from one page to the other during page execution. The major difference between them is that in Server.Transfer (as the name suggests), the transfer is done by the server and in Response.Redirect, it is done by the browser.
Q #18) Define Web Services in ASP.net.
Answer: Web Services are the software services that serve from one machine to another using a network. These services make use of XML and provide SSL and WSS for data transmission.
Q #19) What is a multilingual website?
Answer: Any website which supports multiple languages is called multilingual websites. The content of these websites are in different languages and can be converted into multiple languages. Some popular multilingual websites include Msn, Facebook, etc.
Q #20) Which object wraps the state or data of a user?
Answer: Session Object.
Q #21) What is a Session Object?
Answer: Session object is an object that stores information about a user’s session. The common information includes name, id, preferences, any changes in the settings, etc. Session Object is initialized when a session starts and is destroyed when the session expires.
Q #22) Explain the difference between Authentication and Authorization.
Answer: Authorization is the process of confirming whether you are an authorized user to access the system. This includes validating the login credentials.
For example, login access to Facebook.
Authentication is the process of providing access to any specific resource in a system. This includes accessing any private data, resource keys, tokens, etc. For example, access rights to view private photos on Facebook.
To summarize, only an authenticated person can be authorized to use resources.
Q #23) Which methods validate all the controls on a page?
Q#24) How can you apply a theme to your ASP.Net Application?
Answer: There is a configuration file called web.config. Inside the web.config file, you can navigate to the <configuration> tag and apply the theme as shown below.
<configuration> <system.web> <pages theme = “your theme name”/> </system.web> </configuration>
Q #25) Does Web Services support data readers like the POM project?
Answer: No it does not. However, it supports data set which can be used to pass input data.
Q #26) What is a Web API? Which protocol is used in a Web API?
Answer: Web API can be defined as an interface that facilitates the communication between a client machine and a web server.
Let’s take a very common scenario of booking a flight on www.makemytrip.com, which is an online travel service that aggregates information from multiple airlines. When you go for a flight booking, you enter information like journey date/ return date, class, etc. and click on search.
This will show you the price of multiple airlines and their availability. In this case, the application interacts with the APIs of multiple airlines and gives access to the airline’s data.
Another example is www.trivago.com which compares and lists down the price, and availability of different hotels from a particular city. This website communicates with the APIs of multiple hotels to access databases and lists down the prices and availability from their website. HTTP protocols are used in Web API.
Q #27) Which library is used by the testers and developers to develop automated tests and create testing tools?
Answer: TestAPI is a library (utility) that is used to create automated tests and testing tools using algorithms.
Q #28) What parameters can you pass in the URL of the API? Can GET and POST use the same URL?
Answer: There are a few parameters that you can pass in your URL to define the complete end-point. These are context keys, document keys or anything that facilitate the API to hit the exact endpoint.
For example, We have to hit the document “test” on Presto with the use of the context key com.express.presto.
In such a case, our URL happens to be https://www.presto.com but the complete end-point will look like
In this way, we can be sure that the endpoint will hit the test document using a specified context key.
Yes, GET and POST will have to use the same endpoint. If you don’t use the same endpoint, then it will be like you are creating a record in one URL and retrieving something else from the other URL and this won’t make any sense.
Q #29) If 200 is for all successful operation then why do we have 201 Response Codes?
Answer: This is a tricky question. As we know, all the HTTP response codes in Web API can be manipulated by the developer and it all depends on the App Dev as how they want to configure the response codes.
Thus, you can have 200 or 201 for all successful operations. In general, 200 stands for a successful operation and 201 for the successful creation of a record.
Q #30) How can you make sure that Web API returns JSON data only?
Answer: In the header portion, you have to pass the value “application/json”.
Q #31) What is a Swagger in Web API?
Answer: Swagger is the most common template that is used in the Web API. This template is used to check the response of an API for different methods that a particular API supports. You just need to click on the verb (GET or PUT), specify tokens, body or payload (if applicable) and click on “try it out”.
Before implementation, every developer will provide you the swagger link on which you can superficially test the API. If not, the same can be achieved using a tool called POSTMAN.
Q #32) Explain Swagger Components.
Answer: As you can see in the above image, there is a URL that ends with /swagger-ui.html. Every Swagger URL ends with the /swagger-ui.html.
Enlisted below are the various components of Swagger:
a) Name of the documentation: Here API Documentation is the name of the documentation.
b) Name of the API: The product controller is the name of the API which will have an API version and a base URL.
c) List of methods that API supports: GET, PUT, POST, and DELETE are the common methods that API supports.
d) Parameters: There are few parameters like id (context key), name (document name), authorization, content-type, etc. that every swagger supports.
e) Submit: After you have entered all the required values, you need to click on the Try it Out button which is the submit button for all swaggers.
Q #33) What are the media types of HTTP Requests and Response?
Answer: Media types are used to specify the formats of the requests, responses, images, and texts.
Media types include:
- Image/Png or Image/Jpg or Image/Jpeg
- Application/json or Application/xml
Q #34) What is BSON in Web API?
Q #35) Write a code snippet to implement the indentation in JSON in Web API.
Answer: Below is the code snippet for indentation.
var json = GlobalConfiguration.Configuration.Formatters.JsonFormatter; json.SerializerSettings.Formatting = Formatting.Indented;
With this, we have come to the end of the tutorial on ASP.Net and Web API Interview Questions. Thorough knowledge of these ASP.Net and Web API interview questions will help you to crack the interview successfully.
We wish you all the best for your ASP.Net and Web API Interview!!