Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to optimize ASP.NET WebForms to perform as fast as ASP.NET MVC?

There's so much hype about ASP.NET MVC these days, but the truth is that ASP.NET webforms is not going anywhere for some time. Is there any way for current developers to optimize ASP.NET webforms to perform as fast as ASP.NET MVC?

I have noticed a significant difference in speed between ASP.NET MVC and ASP.NET webforms. MVC is a lot snappier and loads pages faster than webforms. Can I achieve the same with ASP.NET webforms by optimizing it? If yes, what would you recommend?

like image 452
Sahat Yalkabov Avatar asked Jul 13 '10 17:07

Sahat Yalkabov


2 Answers

In your page directive do the following:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs"
    Inherits="TestApp._Default" EnableViewState="false" %>

Mainly turning off ViewState will make up a majority of the difference in page performance. Also limitting the use of WebForm controls will also make your HTML served up a lot less verbose as they tend to produce very verbose HTML.

On the other hand doing so is almost like cutting away some of the large advantages to WebForms. The controls and the abstracting of state by using ViewState is some of the main reason's why WebForms is so popular today.

I do a lot of WebForms development still and do MVC as well. Having knowledge of both and their strengths will help you create a performant app in either framework. When I create any new WebForms app, the first thing I do is to wrap pages in a Panel make sure to disable ViewState for the entire panel. As I develop, and I find a use for the ViewState (eg. to save me time or simplify things) I turn it on case by case so I understand why I am using it and make a consious decision to add the overhead to my page.

WebForms can be just as fast as MVC if you approach your web app with performance in mind but it's very easy to make it much slower if you want to just ignore performance and just get the app done.

like image 83
Kelsey Avatar answered Oct 20 '22 16:10

Kelsey


The technology does not matter, how you implement your application does. One can argue ViewState would make a difference but that is also an implementation detail. ViewState is not required and you can also leave it on the server. At the end of the day both of these technologies deliver HTML over HTTP.

like image 36
rick schott Avatar answered Oct 20 '22 17:10

rick schott