I have a large application which Just afew Pages of that uses ViewState.
I want to know whats happen if I Disable ViewState in MasterPages and enable it in pages which really using it.
ViewState Contents are too large in my application and cause to in crease page size. I want to reduce page size with disabling ViewState, Is it a good solution when I reaaly do not use ViewState ?
And , If I disable ViewState, Will my application work as good as when ViewState was Enable ?
As I suggested in your recent question, you should really read this article:
TRULY understanding ViewState
(actually, I think every ASP.NET developer should be forced to read and understand that article :-).
Then you will be able to make the correct decision. Also, the time spent reading and understanding the article will be a very good investment for the future.
If you disable ViewState, and a page needs it, the page will no longer work.
Related
Are there any tools for analyzing the controls in an ASP.NET page, to make sure they do not need to use the viewstate?
We are trying to optimize a website written in C# asp.net 3.5 , and wanted to see if a tool would automatically analyze the project and make recommendations.
I'm not familiar with tools specifically for analyzing the ViewState of different elements on an asp.net page.
I almost never save ViewState of table elements like DataGrid or GridView, since these element have HUGE ViewState objects that aren't neede most of the time. You need to think logically which element's state you need to save for the user.
You can also enable 'Trace' (Enabling Trace), proxy sniffer tools like Fiddler and different performance add-ons (like YSlow for FireFox) to see how much data you're sending to the server on each call and how much you're getting back, where the time is being taken up mostly, and try to see which data isn't necessary.
A good article on improving performance of an asp.net web application : http://www.dotnetfunda.com/articles/article45.aspx
The only one I know of is a FireFox extension called Viewstate size, which displays the size of the viewstate in the bottom status bar in the browser. You can see the size on the unmodified page, make some code changes and refresh the browser to see if your changes made any difference in the viewstate size.
As I mention in an earlier question, I am having trouble with the performance of a web site... Some SQL queries are killing the server. But, as the title of this post mention, I looked at the OutputCache page directive to improve performance of the site.
Although, I came across some questions regarding this directive:
1- If I have a web-user control that declares an OuputCache directive in a page that has one too, which one will "win" ?
2- What's the best pratice regarding the duration ? I'd love to have a sliding window too.
Thanks for your help and please visit http://www.developerit.com
On a request where neither are cached, both the page and the control will be created, and then added to the output cache. If the page is cached, the control will not be created, regardless of whether it's in the cache or not--its markup is contained in the cached copy of the page. If the page is not cached and the control is, the cached markup of the control will be used in the page.
Here's a good article on Output caching: https://web.archive.org/web/20211020111708/https://www.4guysfromrolla.com/articles/121306-1.aspx.
Generally, you seem to be looking at Page and Fragment caching. What you want to do is cache the Page, if you can, as that will give you the best performance benefit. But, if you have regions on the page that must change dynamically per user, eg: you are saying 'Hi {username}' at the top of the page, then you need to look at Fragment caching.
Fragment caching is not as effective as page caching, since the output has to be stitched together from cached info and dynamic info, but it's usually still MUCH better than NO caching!
It's a bit of an art, to tweak the caching depending on what the page does and the load on the database, but it can make a page load many Orders of Magnitude faster than non-cached.
FYI - if the db queries are killing the site you may want to also look at taming them and/or caching their output individually, so that you don't have to keep hitting the database for the same information.
Also understand the 'varyByParam' for caching is pretty useful too - say you have a page in 3 languages, you can cache a page for each language by using the varyByParam, as long as your Url some sort of language component that the varyByParam can pick up.
HTH,
Lance
I think
beestings change the html every time.
this means html is not able to be cached.
am I right?
I assume that by beesting, you mean some sort of random number in the URL.
Yes this will (usually) stop caching of pages. Some browser may still cache some or all of the page.
As to whether not to avoid it. Would caching a page stop it working as it should? If your page has fairly random content or content the changes often, users would not see this if the page is cached.
If you can avoid the need to stop caching, pages will be able to load faster. Which makes for a happy user.
Old, old question, but anyway... no. You actually can "cache some or all of the response generated by an ASP.NET page, referred to in ASP.NET as output caching". You can read more at this Microsoft page.
For those still wandering, bee stings are special tags used in Microsoft's asp.NET to hold server-side code, much like PHP would do. It is, or was, very common to keep simple code inline, although having significant amount of code in bee stings is considered a bad practice by Microsoft themselves.
But as a rule, yeah, it can be cached.
I am new to asp.net and have got some concerns about the bloated viewstate on a small site I'll be maintaining.
Since I actually don't want to learn asp.net (mvc looks interesting though), my question is if I should care about this potential issue or just wait 4 years until its time to rewrite the site....
Hopefully some of you have some experience or already have done a proper research to help me decide if it's worth the time to do something about it.
I am not interested in workarounds since if this is a serious issue I have found info about different ways to reduce the viewstate. (Although it requires me to understand the framework and code.)
Thanks.
some search engines only process the first few KBs of the page if the page size is large. As viewstate is a hidden input at the top of the form/page this can impact SEO as the actual content of the page may not get fully processed by the search engine if there is too much viewstate. Look into moving the viewstate to the bottom of the page.
http://www.hanselman.com/blog/MovingViewStateToTheBottomOfThePage.aspx
It can cause excessive page weight but this will not hurt your standing with the search engines. ViewState is stored in a hidden input which are mainly ignored by search engines.
I know this thread is old but in ASP.Net every control including the page itself has a property called EnableViewState. All one has to do is turn it to false if they do not need a control to maintain state or for that matter the page itself
When designing a ASP.net WebForm application what are some important steps to take (or hacks if you like to use the term) to ensure the best possible performance (in terms of speed, stability, and scalability)?
Here's a good Best Practices written by microsoft. Chapter 6 is specific to ASP.NET, but the whole document is .NET in general.
http://msdn.microsoft.com/en-us/library/ms998530.aspx
You've got a ton of material, directly from Microsoft here.
Also a checklist is available if you want condensed information.
Just a couple, in addition to the good advice already given,
Don't put every single page in a webform, not everything needs it - The default behaviour from VS is to give you a master page that wraps a form around everything, and a lot of people seem to stick with that. In my experience, some controls can render 30% faster outside of a webform, so if you're just parsing a querystring then reading something from a database, leave the form at home if you can. Even getting your navigation out of the form will help.
Don't use a server control when plain old HTML will do - does it really require a asp:linkbutton or asp:hyperlink just to go to the FAQ page etc. Plain hyperlinks work just fine in asp.net, but some people seem to get stuck on the idea of using runat="server" for everything.
There is a phenominal book on this subject by one of the Yahoo guys, Steve Souders. It taught me a lot.
Or you can just watch this video. It's a high level overview of the same information - you can pick up a lot in 45 minutes by watching this.
NOTE: This content is not WebForms-specific. It's general best practices for the web, and it is what you need if you are trying to roll out a high performance website.
Big # 1 tip: turn off viewstate in the web.config. That should have been the default, if you need it for a control turn it on on a control by control basis.
My other piece of advice is stay the hell away from *view controls. Use repeaters and find a good 3rd party grid control. The really "magical" controls that ship with asp tend to be perf hogs, and in general just not a good idea anyways (with the possible exception of ListView)
1 - Turn on content compression on iis
2 - Cache everything you can
This will do for the majority of webapps out there.
I am not sure about content compression when the content involves html with js doing ajax stuff. Sometimes the blocks of data exchanged through ajax are small and in this case (and if that is considered content) compression often hurts instead of helping. For example, a four bytes block of data produces a compressed block of 100+ bytes.