Web API CONTROLLER WITH MULTIPLE GETS

You might think that ApiController in ASP.NET  MVC will support multiple GET methods out of box, surprisingly it does not.

For more details, refer to my Open source security project on CodePlex at http://applicationsecurity.codeplex.com/

 

Let us take simple example, you are planning to abstract all user management related logic in a REST service. Your controller might look like this:

image

And you want to call your VerifyUser passing all the parameters. Let us see what happensā€¦

SNAGHTML9d75d30

You are planning to add more methods like LogOff, ResetPassword etc. What do you do?

Solution is simple: You need to add an additional routing BEFORE your default routing as follows:

image

Let us what happens now:

SNAGHTML9dc933d

In order to solve this problem, you need to make the following change in your controller:

image

 

Now the final response

SNAGHTML9e7c9a8

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: