Using WebAPI with ASP MVC 3

If you are like me where in your organization you are using the membership provider that came with ASP MVC 3 template but you also have the need to provide RESTful services from within the same application and would really really like to use the awesome WebAPI, here is what you need to do:

  1. Create a brand new MVC 3 internet application or open up your existing application
  2. Install the following NuGet Package using the package manager console:

  3. Open the Global.asax file and add the following route after this routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); line as shown:

  4. Also ensure that you have used or imported System.Web.Http depending on C# / VB in Global.asax like so:

  5. Add a new WebAPI controller using the Add -> New Item context menu option or just use Ctrl + Shift + A keyboard shortcut.

I believe this is a lot easier than starting a MVC4 application and trying to incorporate the membership provider into that.

Cheers!

4 thoughts on “Using WebAPI with ASP MVC 3

  1. Craig

    Thank you for posting. I have an app that is MVC 3 and needed to add an api controller and this was so simple to do and worked perfectly.

     
    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *