Frequently Asked Interview Questions

1. What is ASP.NET Web API?
Answer: ASP.NET Web API is a framework for building HTTP services that can be consumed by various clients, including web browsers and mobile devices. It is designed to work with HTTP and is particularly suitable for RESTful service development.
2. Explain the difference between ASP.NET Web API and WCF (Windows Communication Foundation).
Answer: • ASP.NET Web API is designed for building HTTP-based services that are lightweight and RESTful, primarily targeting web and mobile clients. • WCF, on the other hand, is a comprehensive framework for building various types of services, including SOAP-based services, TCP services, and more. It is more complex and versatile but may be overkill for simple HTTP services.
3. What are the key HTTP verbs used in ASP.NET Web API, and what are their meanings?
Answer: • GET: Used to retrieve data from the server. • POST: Used to create a new resource on the server. • PUT: Used to update an existing resource on the server. • DELETE: Used to delete a resource on the server. • PATCH: Used to partially update a resource on the server.
4. Explain the purpose of routing in ASP.NET Web API.
Answer: Routing in ASP.NET Web API determines how incoming HTTP requests should be mapped to specific controller actions. It allows you to define URL patterns and map them to specific actions in your API controllers.
5. What is content negotiation in ASP.NET Web API?
Answer: Content negotiation is the process by which ASP.NET Web API selects the appropriate response format (e.g., JSON or XML) based on the client's requested format (typically specified in the Accept header of the HTTP request).
6. What is Model-View-Controller (MVC) in the context of ASP.NET Web API?
Answer: MVC is an architectural pattern that separates the application into three interconnected components: Model (data), View (presentation), and Controller (logic). In the context of ASP.NET Web API, it primarily refers to the Controller component, which handles HTTP requests and generates HTTP responses.
7. Explain attribute routing in ASP.NET Web API?
Answer: Attribute routing is a feature that allows you to define routes using attributes on your controller actions. This provides a more declarative and intuitive way to specify how incoming requests should be mapped to actions.
8. What is Cross-Origin Resource Sharing (CORS), and why is it important in a Web API?
Answer: CORS is a security feature that allows web pages from one domain to request and access resources on a different domain. In a Web API, CORS is essential for enabling cross-domain requests, such as those made by web applications running.
9. How can you secure an ASP.NET Web API?
Answer: There are several ways to secure an ASP.NET Web API: • Token-based authentication (e.g., JWT). • OAuth or OAuth2 for authentication and authorization. • API keys. • SSL/TLS for secure communication. • Role-based or claims-based authorization.
10.Explain the purpose of the [FromBody] and [FromUri] attributes in Web API parameter binding. Answer: • [FromBody] is used to bind parameters from the request body. It is typically used with complex objects in POST and PUT requests. • [FromUri] is used to bind parameters from the URI (query
Latest News