dtjmsy
dtjmsy

Reputation: 2752

asp.net mvc 4 webapi advantage over traditional asp.net mvc 3 ajax call

I am testing the new web api from asp.net mvc 4, I don' t see much advantages over a current action controller call from existing asp.net mvc 3.

action controller from mvc 3 can return json very much the same manner as web api.

I have 2 questions concerning the web api:

  1. When should we use web api over standard action controller jsonresults ?
  2. How can we protect the web api, with granted access from differents plateforms ( authorize mobiles apps, pr other websites ) ?

Thanks

Upvotes: 1

Views: 1534

Answers (1)

heads5150
heads5150

Reputation: 7443

You're comparing apples with oranges. The Web Api framework has been developed as a viable replacement for WCF or other ASP .Net service based technologies. The Web Api framework is not intended to be a replacement for MVC. To answer your questions

  1. If you're not exposing your API or not working in an environment where you need services (SOA to support mobiles and/or different OS's for instance) you can use standard action controller json results from the MVC controllers. In fact there's no reason you can't use 'standard' MVC controller JSON Results with mobile devices or different OS's, but the Web API exposed extra useful functionality such as Content Negotiation and better HTTP Verb handling that makes it much more useful in a SOA environment.
  2. The same way you can protect MVC applications by using custom action filters either an extension of the Authorisation action filter or a completely bespoke action filter. Within the filter you could easily check a white list of IP addresses or check the User-agent of the current Http request.

Upvotes: 9

Related Questions