Explore topic-wise InterviewSolutions in .

This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.

1.

How to unit test Web API?

Answer»

Using Web API tools like Fiddler, we can perform UNIT TESTING in Web API. Fiddler is basically a free debugging proxy for any browser that can be USED to compose and execute various HTTP requests to Web API and CHECK HTTP response. It is simply used for testing restful web services. It allows one to inspect and check both incoming and outgoing data to monitor and modify requests and responses before the browser receives them.  Below is given some SETTING that is needed to be done fiddler:

Fiddler – Compose Tab -> Enter Request Headers -> Enter Request Body and then execute.

2.

Explain method to handle error using HttpError in Web API?

Answer»

CreateErrorResponse is an extension METHOD that can be USED in Web API controller methods to RETURN error codes and error MESSAGES. It creates an HttpError object and then wraps it inside an HTTPRESPONSEMESSAGE object. 

3.

Web API uses which library for JSON serialization?

Answer»

JSON.NET LIBRARY is used by Web API for JSON SERIALIZATION

4.

What is the use of DelegatingHandler?

Answer»

DelegatingHandler is used to DEVELOP a custom Server-Side HTTP MESSAGE Handler in ASP.NET Web API. It is used to represent Message Handlers before routing in Web API. 

5.

What parameters can be passed in the URL of API?

Answer»

Context keys, DOCUMENTS keys, or anything that INITIATES API to hit the EXACT end-point are few PARAMETERS that one can pass in the URL to define the complete end-point.  

6.

Name method that validates all controls on page?

Answer»

Page.Validate()

7.

What is CORS in Web API?

Answer»

CORS (Cross-Origin Resource Sharing) is basically a mechanism that allows one to MAKE requests from one website to another website in a browser that is normally not allowed by another POLICY CALLED SOP (Same Origin Policy). It SUPPORTS secure cross-origin requests and data transfers among clients or browsers and servers. Here, cross-origin request means requests coming from DIFFERENT origins. CORS simply resolves the same-origin restriction for JavaScript. One can enable CORS for web API using the respective web API package or OWIN middleware. 

8.

Difference between HTTP GET vs HTTP Post?

Answer»

HTTP (HYPERTEXT Transfer Protocol) simply manages request-response between client and server. It works as a request-response protocol between client and server. 

HTTP GET: This method is used to get information or data from a respective server at a specified URL.

Example: 
GET/RegisterStudent.asp?user=value1&pass=value2

HTTP POST: This method is used to send data or information to respective servers. 

Example:
POST/RegisterStudent.asp HTTP/1.1 
Host: www.guru99.com  
user=value1&pass=value2  

HTTP GETHTTP POST
Its parameters are included in the URL.Its parameters are included in the body.
This method is used to request data from specified resources and has no other effect.This method is used to send data to a server to create or update resources.
It carries a request parameter appended in the URL string.It carries request parameters in the message body that make it a more secure way of sending data or information from the client to the server.
Request method USING GET is cacheable.Request method using POST is not cacheable.
GET requests are less safe than POST.Post request is SAFER than GET.
There is a restriction on data type in GET method and only ASCII characters are allowed.There are no restrictions on data type in this method and BINARY data is also allowed.
Data is visible to everyone in the URL.Data is not displayed in the URL. It is present in the payload.
9.

What is content negotiation in ASP.Net Web API?

Answer»

Content negotiation is BASICALLY a process of selecting the best REPRESENTATION from multiple REPRESENTATIONS that are available for a GIVEN response. It simply allows one to choose rather than negotiate content that one wants to get in response. It is performed at the server-side. In simple words, it chooses the best media type for matters to return a response to an INCOMING request. 

10.

Can we return View from ASP.NET Web API method?

Answer»

No, we cannot return the view from the ASP.NET WEB API method. ASP.NET web API DEVELOPS HTTP services that provide RAW data or information. ApiController in ASP.NET MVC application only renders data that is serialized and sent to the client. One can use a controller to provide normal VIEWS

11.

What is HttpConfiguration in Web API?

Answer»

It is CONSIDERED as the main class that includes different properties with help of which one can override the DEFAULT BEHAVIOR of Web API. 

Some properties are given below:

  • DependencyResolver: It SETS or gets a dependency resolver for dependency injection.
  • Services: It gets web API services.
  • ParameterBindingRules: It gets a collection of rules for how parameters should be bound.
  • MessageHandlers:  It sets or gets message handlers.
  • FORMATTERS: It sets or gets media-type formatters.
12.

Which .NET framework supports ASP.NET Web API?

Answer»

.NET FRAMEWORK 4.0 GENERALLY supports the first VERSION of ASP.NET WEB API. After that, .NET Framework 4.5 supports the latest version of web API i.e., ASP.NET Web API 2.

13.

What are Exception filters in ASP.NET Web API?

Answer»

Exception filter is GENERALLY used to HANDLE all unhandled exceptions that are generated in web API. It implements IExceptionFilters interface. It is the easiest and most flexible to implement. This filter is executed whenever the CONTROLLER method THROWS any unhandled exception at any stage that is not an HttpResponseExecption exception. 

14.

HOW to secure ASP.NET Web API?

Answer»

Web API has become key to PROGRAMMING web-based interactions. It can be accessed by anyone who knows the URL. Therefore, they have become targets for hackers. One needs to SECURE Web API by controlling Web API and by deciding who can and who cannot have ACCESS to Web API. There are basically two ways or techniques that make our Web API more secure. 

Authentication: It is a process that helps to identify and check users by their credentials such as password, USERNAME, etc. To have access to the web API, firstly user credentials are needed to be passed in the request header. If user credentials are not passed into the request header, then the server returns 401 status code (unauthorized). The best authentication to be used is OAuth 2.0. 

Authorization: It is a process that helps to decide whether or not a user has access to perform an action. Authorization filters are used to implement authorization.

15.

What is ASP.NET Web API routing?

Answer»

Routing is the most important part of ASP.NET Web API. Routing is a way how Web API MATCHES a URI to an action. It is basically a process that decides which action and controller should be called. The controller is basically a class that HANDLES all HTTP requests. All public methods of CONTROLLERS are basically known as action methods or just actions. Whenever a Web API framework receives any type of request, it routes that request to action. 

There are basically TWO ways to implement routing in Web API as given below:
Convention-based routing: Web API supports convention-based routing. In this type of routing, Web API uses route templates to select which controller and action method to execute. 

Attribute-based routing: Web API 2 generally supports a new type of routing known as attribute routing. As the name suggests, it uses attributes to DEFINE routes. It is the ability to add routes to the route table via attributes. 

16.

What are the main return types supported in ASP. Net Web API?

Answer»

It SUPPORTS the following RETURN TYPES:

  • HttpResponseMessage
  • IHttpActionResult
  • Void
  • Other types such as STRING, int, ETC
17.

WCF is replaced by ASP.NET Web API. True/False?

Answer»

WCF: It is a framework used for DEVELOPING SOAP (Service Oriented Applications PROTOCOLS). It also supports various transport protocols as given above. 
ASP.NET Web API: It is a framework used for developing non-SOAP-based services. It is limited to HTTP-based services.

No, it's not true that ASP.NET Web API has replaced WCF. WCF was generally DEVELOPED to DEVELOP SOAP-based services. ASP.NET Web API is a new way to develop non-SOAP-based services such as XML, JSON, etc. WCF is still considered a better choice if one has their service using HTTP as the transport and they want to move to some other transport LIKE TCP, NetTCP, MSMQ, etc. WCF also allows one-way communication or duplex communication. 

18.

What do you mean by Caching and What are its types?

Answer»

Caching is basically a technique or process of storing data somewhere or in the cache for future REQUESTS. The cache is a temporary storage area. Caching keeps all frequently or recently accessed files or data in the cache memory and accesses them from the cache itself rather than actual ADDRESS of data or files. The cache interface simply improves the storage mechanism for request/response object pairs that are being cached.

Advantages of Caching:

  • It is considered the best solution to ENSURE that data is served where it is NEEDED to be served that too at a high level of EFFICIENCY which is best for both client and server.
  • It delivers web objects faster to the end-user.
  • It reduces load time on the website server.
  • It leads to faster execution of any process.
  • It decreases network costs.

Types of Caching:
There are basically three types of caching as given below:

  • Page Caching
  • Data Caching
  • Fragment Caching
19.

What is the difference between ApiController and Controller?

Answer»

APICONTROLLER: It is used to return data that is arranged in series and then sent to the client.

public CLASS TweetsController : ApiController{         // GET: /Api/Tweets/         public List<Tweet> Get()      {          return Twitter.GetTweets();       }}

CONTROLLER: It is used to provide normal views.  

public class TweetsController : Controller {         // GET: /Tweets/  [HttpGet]  public ACTIONRESULT Index()       {              return JSON(Twitter.GetTweets(), JsonRequestBehavior.AllowGet);        }}
20.

What is the use of HttpResponseMessage?

Answer»

It is used to set response values such as header and status control. It simply allows us to work with HTTP PROTOCOL. It represents HTTP response messages that encapsulate DATA and status code. 

// GetEmployee action public HttpResponseMessage GetEmployee(INT id) { EMPLOYEE emp = EmployeeContext.Employees.Where(e => e.Id == id).FIRSTORDEFAULT(); if (emp != null) { return Request.CreateResponse<Employee>(HttpStatusCode.OK, emp); } else { return Request.CreateErrorResponse(HttpStatusCode.NotFound, "Employee Not Found"); } }
21.

What are new features used in ASP.NET Web API 2.0

Answer»

ASP.NET Web API INCLUDES a number of NEW exciting features as given below:

  • Attribute Routing
  • CORS (Cross-Origin Resource Sharing)
  • OWIN (Open Web Interface for .NET) self-hosting
  • IHttpActionResult
  • Web API OData
22.

What are the advantages of using ASP.NET Web API?

Answer»

Some of the core advantages of using ASP.NET Web API are given below:

  • It provides the best platform for developing RESTful applications on .NET Framework.
  • It works the same way that HTTP works with help of HTTP verbs such as GET, POST, PUT, DELETE for all crud operations.
  • It provides enough flexibility in Web API creation.
  • It completely supports routing.
  • It also supports model binding, validation, Odata (Open Data Protocol) that allows creation and consumption of RESTful APIs.
  • It has the ability to DEVELOP custom help and test pages with help of ApiExplorer.
  • One can develop non-SOAP-based services such as plain XML, JSON strings, etc.
  • It also INCREASES the TDD (Test Data-Driven) approach in the development of RESTful services. 
23.

What is ASP.NET Web API?

Answer»

ASP stands for ACTIVE server pages. ASP.NET is an updated version of legacy ASP. It is a framework that is used for developing HTTP services to PROVIDE RESPONSES to client requests. It can be accessed in different applications on different platforms. It is provided by Microsoft open-source technology for developing and consuming HTTP-based services on top of .NET Framework.  It is very easy to build HTTP services using ASP.NET WEB API. These services can be used by different clients as given below:

  • Desktop Applications
  • Mobile Applications
  • IOTs
  • Browsers