1

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

2
  • I suggest reading a good introduction to WebApi. There's way too much about WebApi and how it's better for returning web service results than an MVC action returning json. Try this one stephenwalther.com/archive/2012/03/05/… Commented Oct 1, 2012 at 1:39
  • Don't ignore self-hosting as a Web API advantage, either. You can't do that with MVC. Commented Oct 1, 2012 at 1:52

1 Answer 1

9

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.
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.