开发者

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 i开发者_如何学编程s 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?


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.


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.


One reason for that is because of ViewState, among other bloated code rendered as part of an <ASP:TextBox>, etc. You should focus on page weight.

Everything else being equal, that is the main performance difference that I'm aware of.


I have noticed a fairly perceivable difference in speed

Perhaps you should properly measure performance in a definable way first. Then, if you do in fact have a difference it will be much more clear where that difference comes from and how to bridge that performance difference.


There is this one thing that can make ASP.NET slow that others mentioned: Viewstate. This is especially true for ajax calls. The complete Viewstate is posted when using UpdatePanels.

That said there is this one thing that will make your ASP.NET site outperform your ASP.NET MVC site: Caching. ASP.NET allows for donut caching: you can define caching rules on a WebControll basis. You can not do this in ASP.NET MVC.

If you realy thing you have a speed problem try to find the botttlenecks. It might be database calls (use sql-profiler to check), it might be html-related (use yslow) or it might the application related (try a profiler like the one from redgate ).


Is this a case of two different tools for two different approaches to solving problems and trying to compare between them?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜