What's the advantage of ASP.NET Web API to ASP.NET MVC Controller? - asp.net-mvc

What's the advantage of ASP.NET Web API to ASP.NET MVC Controller?
As far as I know, IIS + WebDAV conflicts with ASP.NET Web API while using "PUT" verb[1].
We can use ASP.NET MVC Controller & JsonResult, etc. to communicate with clients, which use HTTP GET+POST and no more verb to get better compatibility, so what's the advantage of ASP.NET Web API to ASP.NET MVC?
And, ASP.NET Web API should only use the desigend teens HTTP verbs. If I'd like to develop a Web API to let a robot JUMP, but JUMP is not a standard HTTP verb. So how to design the url? http://localhost/api/robot/jump ? But it is not RESTful(RESTful urls should not contain verb).
reference:
[1] http://forums.iis.net/t/1163441.aspx

If you are asking about the difference between Asp.Net application .cs files and controllers in MVC.
We can navigate to required method in MVC depending upon requirement but this is not possible in Asp.Net web.
Always, firing the page load event will not happen.
We can return partial results/Json results/Javascript results and so on.
Unlike Asp.Net life cycle, MVC has its own page life cycle.
Regards,
Pavan.G

Related

Integrating ASP.Net Web API With MVC

how to create a web application using the ASP.NET Web API 2 project template and do some data operations like reading the data from the database and calling the Web API Controller method in the MVC Controller and call the adjacent view? any resources for that? I found one but it doesn;t go into much detail
http://www.c-sharpcorner.com/UploadFile/4b0136/integrating-Asp-Net-web-api-with-mvc-basic-infrastructure-by/
The below example provides a detailed explanation on how to call WebApi from a C# app, you can follow same for the asp.net mvc application also
http://www.asp.net/web-api/overview/advanced/calling-a-web-api-from-a-net-client

ASP.NET MVC and AngularJS authorization

I am currently at the beginning process of starting a new application and am quite new to MVC and Angular. So far i have created a custom authorize attribute using asp.net MVC, this enables me to use the [Authorize] tag. Is it possible to use with an AngularJS front-end?
Any resources that will point me in the right directions would be appreciated.
AngularJs is really good for single-page-applicaitons (SPA). So just separate your front-end and back-end layers. Use Angular to implement all the views and front-end stuff. Use ASP.NET WebAPI to expose REST API for front-end (and maybe mobile) app.
A few useful links:
Angular Routing module
ASP.NET WebAPI Bearer token authorization with AngularJs
Routing in SPA with AngularJs
The answer is YES! So you can still benefit from ASP.NET MVC features like authentication and authorization etc. and still use AngularJS on the client.
I actually had the same question and after a bit of research I discovered the following.
It's true we should embrace SPAs (single page apps) but at the same time we should not just discard mature server-side frameworks such ASP.NET MVC. You can simply have a hybrid web app or mini SPA as we also call them. These web applications use normal ASP.NET MVC routing to show views and then, once the view loads you can leave all the responsabilities to AngularJS. Miguel Castro uses the term SPA silos. Plus you can benefit from AngularJS' routing as well. Miguel Castro also explains how to use them both together to get the best of server and client side. I really suggest seeing his presentation (link below).
In that way you can still benefit from ASP.NET MVC great features like Authentication, Authorization and others but still have AngularJS run your views.
I got this answer on the following locations that you definitely should check out:
Miguel Castro: AngularJS for ASP.NET MVC Developers
PluralSight - Cooper, Eames: AngularJS for .NET Developers
StackOverflow: Mixing Angular and ASP.NET MVC/Web api?
StackOverflow: ASP.NET MVC and Angular JS tipping point

How does IIS recognize that request is for MVC Controllers or webforms Pages?

When the Application pool receives a request, it simply passes the request to worker process (w3wp.exe) . The worker process “w3wp.exe” looks up the URL of the request in order to load the correct ISAPI extension. ISAPI extensions are the IIS way to handle requests for different resources. Once ASP.NET is installed, it installs its own ISAPI extension (aspnet_isapi.dll) and adds the mapping into IIS.
Si If that's true, my question is how does it recognize which extensions to be loaded
for that request?? MVC / Web Forms?
When and where does the IIS come to know that a request is for MVC or WebForms Application?
How framework decide which Modules should handle the request and decide to render page content or views in MVC.
hen and were the IIS come to know that request is for MVC or WebForms Application?
They are both ASP.NET applications so it doesn't need to recognize that. The aspnet_isapi.dll is perfectly capable of serving both types of applications (which are actually a single type called ASP.NET).
ASP.NET MVC is just a custom handler added to the ASP.NET pipeline.
That all is about the standard IHttpModule and IHttpHandler infrastructure. See complete description here Routing with ASP.NET Web Forms and here How ASP.NET MVC Routing Works and its Impact on the Performance of Static Requests

Classic ASP integrated with ASP.NET MVC

I have a classic asp project and a teammate created a new functionality, but it's in asp.net mvc. I also know how to work with mvc, but I never used classic asp and mvc together.
For example, is it possible, in this classic asp project, to have a link that will redirect to a mvc page on the same project?
Thanks!!
Yes, you can have a link point to any other page you'd like regardless of technology. Likewise for a redirect. To redirect in classic ASP, use Response.Redirect
Absolutely, the pages (and that term is used lightly in the MVC side of things) can link between each other without any problems. Now, any built-in authentication or session management or anything like that will be considerably more challenging, but if all the sites need to do is link to each other then they can do this like any other two websites. The ASP pages can host manually-crafted (vs. HtmlHelper-crafted) links to the MVC actions, and can host forms that post values to the MVC actions (provided the field names line up properly).
There's nothing inherently special about the MVC actions. They're just handling HTTP GET/POST requests like anything else.

Which's the best performance between Asp.net MVC controller VS. Wcf for Silverlight Application?

I found that Asp.net Mvc controller can serve both Asp.net Mvc View and Silverlight application via DynamicActionResult(It can be Simple Action Result or Json Action Result depend on request type). So, I have 3 options for creating middle-tier for Silverlight application.
Pure WCF Service Every request to WCF must be declare in interface. So, it's strongly-typed connection.
Asp.net MVC Controller It can serve both Asp.net MVC View and Silverlight application at the same time.
Using both of them I found that it's possible to doing this by using the answer in the following link. I think, It doesn't good idea for creating both of them.
WCF Service with Asp.net MVC application
Which's the best performance between WCF Service and Asp.net MVC Controller?
Thanks,
Do you have the kind of service that would benefit from caching? If so, my testing says that MVC with Output Caching turned on is very much faster than WCF.

Resources