Nizamuddin Siddiqui has Published 2303 Articles

How to do Web API versioning with URI in C# ASP.NET WebAPI?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 19-Aug-2020 12:26:20

781 Views

Once a Web API service is made public, different client applications start using our Web API services. As the business grows and requirements change, we may have to change the services as well, but the changes to the services should be done in way that does not break any existing ... Read More

How can we restrict access to methods with specific HTTP verbs in C# ASP.NETWebAPI?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 19-Aug-2020 12:19:50

2K+ Views

The HTTP verbs comprise a major portion of our “uniform interface” constraint and provide us the action counterpart to the noun-based resource. The primary or mostcommonly-used HTTP verbs (or methods, as they are properly called) are POST, GET, PUT, PATCH, and DELETE. These correspond to create, read, update, and delete ... Read More

How can we assign alias names for the action method in C# ASP.NET WebAPI?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 19-Aug-2020 12:14:16

3K+ Views

A public method in a controller is called an Action method. Let us consider an example where DemoController class is derived from ApiController and includes multiple action methods whose names match with HTTP verbs like Get, Post, Put and Delete.Examplepublic class DemoController : ApiController{    public IHttpActionResult Get(){     ... Read More

What are the different types of filters in C# ASP.NET WebAPI?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 19-Aug-2020 12:09:58

13K+ Views

Filters are used to inject extra logic at the different levels of WebApi Framework request processing. Filters provide a way for cross-cutting concerns (logging, authorization, and caching). Filters can be applied to an action method or controller in a declarative or programmatic way. Below are the types of filters in ... Read More

How to resolve CORS issue in C# ASP.NET WebAPI?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 19-Aug-2020 11:57:44

7K+ Views

Cross-Origin Resource Sharing (CORS) is a mechanism that uses additional HTTP headers to tell browsers to give a web application running at one origin, access to selected resources from a different origin. A web application executes a cross-origin HTTP request when it requests a resource that has a different origin ... Read More

How to return custom result type from an action method in C# ASP.NET WebAPI?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 19-Aug-2020 11:54:42

1K+ Views

We can create our own custom class as a result type by implementing IHttpActionResult interface. IHttpActionResult contains a single method, ExecuteAsync, which asynchronously creates an HttpResponseMessage instance.public interface IHttpActionResult {    Task ExecuteAsync(CancellationToken    cancellationToken); }If a controller action returns an IHttpActionResult, Web API calls the ExecuteAsync method to create an ... Read More

What are the various return types of a controller action in C# ASP.NET WebAPI?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 19-Aug-2020 11:52:00

8K+ Views

The Web API action method can have following return types.VoidPrimitive Type/Complex TypeHttpResponseMessageIHttpActionResultVoid −It's not necessary that all action methods must return something. It can have void return type.Exampleusing DemoWebApplication.Models using System.Web.Http; namespace DemoWebApplication.Controllers{    public class DemoController : ApiController{       public void Get([FromBody] Student student){       ... Read More

What is the difference between FromBody and FromUri attributes in C# ASP.NETWebAPI?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 19-Aug-2020 11:46:27

7K+ Views

When the ASP.NET Web API calls a method on a controller, it must set values for the parameters, a process called parameter binding.In order to bind a model (an action parameter), that would normally default to a formatter, from the URI we need to decorate it with [FromUri] attribute. FromUriAttribute ... Read More

What is the difference between Task.WhenAll() and Task.WaitAll() in C#?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 19-Aug-2020 11:40:59

8K+ Views

The Task.WaitAll blocks the current thread until all other tasks have completed execution. The Task.WhenAll method is used to create a task that will complete if and only if all the other tasks have completed.If we are using Task.WhenAll we will get a task object that isn’t complete. However, it ... Read More

How to download a file from a URL in C#?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 19-Aug-2020 11:37:22

9K+ Views

A file can be downloaded from a URL using web client. It is available in System.Net namespace.The WebClient class provides common methods for sending data to or receiving data from any local, intranet, or Internet resource identified by a URI.The web client can be said as an application or web ... Read More

Advertisements