ASP.Net Web API Interview Questions

    1 Votes

31) How to enable tracing in Web API?

To enable tracing place below code in –“Register” method of WebAPIConfig.cs file.
32) Explain how Web API tracing works?

Tracing in Web API done in façade pattern i.e, when tracing for Web API is enabled, Web API will wrap different parts of request pipeline with classes, which performs trace calls.

33) Can we unit test Web API?
Yes we can unit test Web API.
34) Explain Authentication in Web API?

Web API authentication will happen in host. In case of IIS it uses Http Modules for authentication or we can write custom Http Modules. When host is used for authentication it used to create principal, which represent security context of the application.

35) Explain ASP.NET Identity?

This is the new membership system for ASP.NET. This allows to add features of login in our application.

Below are the list of features supported by ASP.NET Identity in Web API –

  • One ASP.NET Identity System
  • Persistence Control

36) What are Authentication Filters in Web API?

Authentication Filter will let you set the authentication scheme for actions or controllers. So this way our application can support various authentication mechanisms.

37) How to set the Authentication filters in Web API?

Authentication filters can be applied at the controller or action level. Decorate attribute – "IdentityBasicAuthentication” over controller where we have to set the authentication filter.

38) Explain method – “AuthenticateAsync” in Web API?

AuthenticateAsync” method will create “IPrincipal” and will set on request. Below is the sample code snippet for “AuthenticateAsync” –

Task AuthenticateAsync(
HttpAuthenticationContext mytestcontext,
CancellationToken mytestcancellationToken

39) How to set the Error Result in Web API?

Below is the sample code to show how to set error result in Web API –

HttpResponseMessage myresponse = new HttpResponseMessage(HttpStatusCode.Unauthorized);
myresponse.RequestMessage = Request;
myresponse.ReasonPhrase = ReasonPhrase;

40) Explain method – “ChallengeAsync” in Web API?

ChallengeAsync” method is used to add authentication challenges to response. Below is the method signature –

Task ChallengeAsync(
HttpAuthenticationChallengeContext mytestcontext,
CancellationToken mytestcancellationToken

41) What are media types?

It is also called MIME, which is used to identify the data . In Html, media types is used to describe message format in the body.

42) List out few media types of HTTP?

Below are the list of media types –

  • Image/Png
  • Text/HTML
  • Application/Json

43) Explain Media Formatters in Web API?

Media Formatters in Web API can be used to read the CLR object from our HTTP body and Media formatters are also used for writing CLR objects of message body of HTTP.

44) How to serialize read-only properties?

Read-Only properties can be serialized in Web API by setting the value “true” to the property –

“SerializeReadOnlyTypes” of class – “DataContractSerializerSettings”.

45) How to get Microsoft JSON date format ?

Use “DateFormatHandling” property in serializer settings as below –

var myjson = GlobalConfiguration.Configuration.Formatters.JsonFormatter;
myjson.SerializerSettings.DateFormatHandling = Newtonsoft.Json.DateFormatHandling.MicrosoftDateFormat;
Page 3 of 4

Popular Videos


How to improve your Interview, Salary Negotiation, Communication & Presentation Skills.

Got a tip or Question?
Let us know

Related Articles

C# Interview Questions
.Net Framework Interview Questions and Answers
ADO.Net Interview Questions and Answers for Freshers, Experienced
ASP.Net Interview Questions and Answers
ASP.Net MVC Interview questions and Answers
WCF Interview Questions and Answers
Top 50 Entity framework interview questions & answers