Ajax performance: ASP.Net MVC vs Webforms - asp.net-mvc

I just switch my website over to MVC from Webforms and I am using ajax very heavily. MVC seems to be slower but I haven't set up anything to record benchmarks.
Does anyone know which is faster for ajax handling and why it's faster?

You shouldn't see any difference from one framework to the next. They are essentially the same with an exception of less things going on in the execution pipeline of the MVC framework, less stored (no state tracking), etc. How are you doing ajax in your site? Are you using partials? Full views? Rendering json or fully formatted html chunks?

A good tool to use for profiling is either Firebug in Firefox, or Fiddler for IE/Chrome.
AJAX is known for being very chatty with the web server without the users knowledge , whereas a Webform is very explicit in showing when it is posting data back to the server.
It could be psychological, but profile the HTTP connections yourself and see!

Related

Necessity of Web APi in MVC Web application

I am quite perplexed over the use of Web Api in a MVC application being developed at my company.I recently joined the project and wondering why they are using this.The application uses JQuery AJAX functionality to pull data for each Tab in a MultiTab Page without refreshing it.
The application here is neither providing data service nor consuming any Web API service.This can be easily achieved without using REST verbs.It is directly connecting to database like a typical web application.
I am holding back myself to raise this question with the team since I haven't used Web API much but has a conceptual idea.
Am I missing something here ?
Microsoft's Web API MVC technology is typically used for external components to interact with the system - not generally a requirement for a standard MVC Web Application.
With that said, I'm not perfectly clear on the architecture. A few points of note:
jQuery AJAX is a perfectly valid (and usually preferred) method to retrieve information for tab pages - it provides a SPA (Single Page Application) "feel" to the site and generally improves performance all around. This does not mean that they're using a Web API
MVC is a framework used for many web applications, including Microsoft's Web API projects as well as ASP.NET MVC Web projects. The use of MVC doesn't mean that they're using a Web API.
A RESTful approach isn't just for Web APIs. Indeed, many find it a cleaner approach when using regular MVC Web Applications, as it tends to be more semantic to what actions are actually being performed (GET to get a view, POST to post data, DELETE, etc.) There's no real reason not to use REST verbs (which are actually just HTTP verbs, but called "REST" when we use them in a certain way). The use of HTTP verbs doesn't mean that we're using a Web API.
To conclude, The MVC Web API framework is it's own technology that's similar to MVC Web Applications, but more geared towards working with non-visual requests and responses, instead tailored to programmatic interfacing.
If this is indeed a Web API being used and not a case of MVC practices that you happen to be unfamiliar with, then yes, I think it's a good question to raise (at least from a technical standpoint - politically, maybe not, but we can't answer that for you).
A typical setup is to have multiple projects, one of which is a Web Application, which makes use of shared project(s) for domain/business classes and data persistence. Additionally, a Web API project is often used to provide access to the system for external components, but this is a separate "presentation layer" project from the aforementioned Web Application.
There may be cases where a Web API application is written as the core interface between the internal system and the rest of the outside world, where the MVC Web Application then interacts with the Web API, but this is a corner case that should only be done with specific reason, in my opinion (unless I misread, this seems to be the case you're stating?)
Using both MVC and WebAPI together in a ASP.NET Web application is quite common. Whilst you can provide HTML through WebAPI and you can provide JSON through MVC it's much cleaner to use the best technology for each.
WebAPI in particular lets you define an API once and then generates JSON, XML, ... for you based on the request.

What are the major differences between Web API and ASP MVC

The title really sums up my question. I have used both technologies but I am uncertain as to what one offers that is substantially different than the other. In essence:
What criteria and/or guidance should one consider when selecting ASP MVC or Web API when designing a restful web application?
Purpose
ASP.NET MVC is focused on making output of HTML easy. ASP.NET Web API is focused on making output of raw data easy.
In the WebForms world, ASP.NET MVC would be equivalent to .aspx pages and ASP.NET Web API would be .asmx.
Although nothing is impossible
While it's possible to make Web API output HTML and MVC output raw data, you will need additional work. For example, making additional classes to handle text/html during content negotiation in Web API, or adding logic to handle OData queries in MVC.
Assumptions
The default assumption for both MVC and Web API are different too. MVC by default assumes user submitted data can come from multiple sources, be it in the query string or in the form.
Web API by default assumes that primitive type comes from query string and non-primitive types comes from the form. It also assumes that you would only want to read the form body once, without caching, to have lower memory usage and better performance.
Going against the defaults requires additional work, that to me, does not make sense at all.
EDIT:
Also, GET AJAX request is blocked by MVC's JsonResult by default to prevent CSRF, while Web API allows GET AJAX request by default.
Update for MVC 6
MVC 6 unifies MVC and Web API and allows you to return ViewResult like in MVC or object like in Web API, and the framework will take care of content negotiation, creating the HTML, JSON or XML for you. Lower memory usage also arrives in MVC, by using its custom pipeline instead of what is provided by System.Web.
So going forward, there's no distinction between the MVC and Web API.

Asp.Net MVC and HTML5 PUSH notification

I would like to have server side event in a full HTML5 application.
Server side I've an asp.net MVC3 web server, which gives HTML pages and JSON results.
What is the best way to integrate some server event? Like a process which can send some text message to client?
I've made some search and found something about a Asp.Net web api, but I don't know what it is and if I can use it with MVC.
You should have a look at http://signalr.net/ library. This blog post is also very informative.
SignalR looks very interesting, but maybe more than you really need. I've often wondered why people don't use Server-Sent Events more often, I haven't had the chance, but it looks like the simplest way of implementing.
Here is an example in MVC if you want to review: http://blogs.microsoft.co.il/blogs/gilf/archive/2012/04/10/using-html5-server-sent-events-with-json-and-asp-net-mvc.aspx

How to integrate DotNetOpenAuth and openid-selector

I created a DotNetOpenAuth MVC 2 project using the visual studio template, and have it working. However, the sign in page takes a long time to load. Not quite sure exactly what is going on in the library, but it seems like there is some kind of javascript slowing down the login image button UI from rendering quickly.
I'd like to instead use the openid-selector on the client, rather than the MVC helpers from the DotNetOpenAuth library. What kinds of client & server hooks is the HtmlHelper in this example hiding?
This post shows how to integrate DotNetOpenAuth and openid-selector:
http://blog.tchami.com/post/ASPNET-MVC-2-and-OpenID.aspx
The openid-selector client, if you're talking about the one like StackOverflow uses, has no server-side hooks at all in the same way that the HtmlHelper's in DNOA use, since the openid-selector makes no AJAX calls back to the server. DNOA's selector control uses AJAX a lot to provide users with an auto-login experience, auto-discovery as they type in the identifier, etc.
So in short, yes, the openid-selector (SO-style) is much simpler and works great with DNOA as well.
And yes, DNOA's built-in AJAX selector loads more slowly. That's something that I (or a volunteer) still need to work on speeding up.

Reverse ajax Comet/Polling implementation for ASP.NET MVC?

I am looking for ASP.Net MVC implementation for reverse ajax comet/polling. Can anyone provide some good link or tutorial
Regards
I suggest you to check PokeIn library.
PokeIn gives you an enhanced JSON functionality to makes your server side objects available in client side. Simply, it is a Reverse Ajax library which makes it easy to call JavaScript functions from C#/VB.NET and to call C#/VB.NET functions from JavaScript. It has numerous features like event ordering, resource management, exception handling, marshaling, Ajax upload control, mono compatibility, WCF & .NET Remoting integration and scalable server push.
There are 2 ASP.NET MVC samples on the link above.
Check out WebSync, a reverse AJAX/Comet server for .NET.
www.frozenmountain.com/websync/

Resources