I saw a few users rated our site down lately and all seems to be from countries far far away. This, I figure, could largely due to the fact that the size of the HTML code generated by our pages has gone wild and made our user sick in waiting.
For your information, I've tried to make our site feature rich by throwing a lot of AJAX server controls from the ASP.NET Ajax toolkit. While the functionality of the site got improved conceivably, the Java Script spit out by such controls also puff up the page size considerably. Another culprit is, as you may have already guessed, the viewstate. I stuff a lot of user controls in the page and each would chip in a lengthy chunk of viewstate that need to be bounced between to the user and the server. What makes the thing worse is that the user controls are there to provide some multi-step wizard type of funciton which would trigger post back multiple times.
Replacing the user control with web service and AJAX backed components can be tempting but I'm more into RAD, especially when my thesis is in the area of biochemistry rather than computer science. What can I do?
The first thing I thought of is to store the Viewstate on the server rather than push it down to the user. ASP.NET 4.0 has made it easy for aspx page to persist the viewstate locally on the server. But for some reason they did not do the same for the user control and their viewstate still need to be stored in the page that contains them.
Compressing the page generated seems to be the logical answer and this again can be easily done especially in IIS 7: A tick in the appropriate checkbox is all you need.
This would compress both the Java Script and Viewstate generated by the user control at the same time. However, it is not the silver bullet that can solve all my problems. Although this would allow the deflated viewstate to be pushed down to the user through a faster downloading pipe, the inflated version would need to be uploaded back to the server via a usually slower uploading link.
Therefore, unlike some post suggested, compressing the viewstate prior whole page compression is still necessary. However, I'm yet to see any solution to do this possibly due to the lack of mechanism to overwrite the save viewstate method or indicating the persistance medium.
Genetics Dot NET
Saturday, 8 October 2011
Monday, 12 September 2011
(Nearly) All tricks to get large file uploaded in ASP.NET
The file upload control in ASP.NET can come in handy when you want to upload files unto your server. It's long been said a file as large as 2 GB can be handled by tweaking a few parameters. However, it turns out that a lot more hurdles are there awaiting to be solved and it is not until today that I finally get it working. Therefore, I though listing all the necessary changes and traps I encountered here together with the solution may benifit a poor fellow like me in the future.
First some brief introduction about my server enviroments and some considerations:
I run a few web applications within our main site and some of the applications would need file upload functionality. We may have new server in the near future to be dedicated to the applications. So instead of making systematic change in machine.config which may not be copied to new machine, all the changes are made in web.config in each application when applicable.
The changes to be made:
1. HTTP max request length limit and request time out limit.
File to modify: web.config of your web application (or machine.config if you preffered).
Content to add/modify:
<system.web>
<httpRuntime maxRequestLength="XXXX" executionTimeout="XXXX"/>
</system.web>
Notice: Request length in KB and timeout val in MINI SECOND.
Comments: These are all the changes need as Google suggested but is just the starting point for me.
2. If URLScan is used, change its request length limit.
File to modify: urlscan.ini, it's in the same folder as URLScan installed, normally C:\Windows\system32\inetsrv\urlscan
Content to add/modify: MaxAllowedContentLength = XXXX
Notice:Content length in BYTE.
Comments: It took me a LONG time to discover this.
3. If session is implemented, change session time out.
File to modify: web.config of your web application (or machine.config if you preffered).
Content to add/modify:
<system.web>
<sessionState timeout="XXXX" />
</system.web>
Notice:Timeout value in MINUTES.
Comments: I store uploaded file name into session variable which would be cleared when session timed out. The upload page also reset it self as the session timed out.
4. If implimented form authentication, change form authentication timeout.
File to modify: web.config of your web application (or machine.config if you preffered).
Content to add/modify:
<system.web>
<authentication mode="Forms">
<forms timeout="XXXX"/>
</authentication>
</system.web>
Notice:Timeout val in MINUTES.
Comments: User would be logged out and redirected to the log in page when file uploading takes longer than this limit.
5. If file uploaded is to be stored into database, change the db connection timeout in data source configuration.
File to modify: The aspx files that handles the file upload.
First some brief introduction about my server enviroments and some considerations:
I run a few web applications within our main site and some of the applications would need file upload functionality. We may have new server in the near future to be dedicated to the applications. So instead of making systematic change in machine.config which may not be copied to new machine, all the changes are made in web.config in each application when applicable.
The changes to be made:
1. HTTP max request length limit and request time out limit.
File to modify: web.config of your web application (or machine.config if you preffered).
Content to add/modify:
<system.web>
<httpRuntime maxRequestLength="XXXX" executionTimeout="XXXX"/>
</system.web>
Notice: Request length in KB and timeout val in MINI SECOND.
Comments: These are all the changes need as Google suggested but is just the starting point for me.
2. If URLScan is used, change its request length limit.
File to modify: urlscan.ini, it's in the same folder as URLScan installed, normally C:\Windows\system32\inetsrv\urlscan
Content to add/modify: MaxAllowedContentLength = XXXX
Notice:Content length in BYTE.
Comments: It took me a LONG time to discover this.
3. If session is implemented, change session time out.
File to modify: web.config of your web application (or machine.config if you preffered).
Content to add/modify:
<system.web>
<sessionState timeout="XXXX" />
</system.web>
Notice:Timeout value in MINUTES.
Comments: I store uploaded file name into session variable which would be cleared when session timed out. The upload page also reset it self as the session timed out.
4. If implimented form authentication, change form authentication timeout.
File to modify: web.config of your web application (or machine.config if you preffered).
Content to add/modify:
<system.web>
<authentication mode="Forms">
<forms timeout="XXXX"/>
</authentication>
</system.web>
Notice:Timeout val in MINUTES.
Comments: User would be logged out and redirected to the log in page when file uploading takes longer than this limit.
5. If file uploaded is to be stored into database, change the db connection timeout in data source configuration.
File to modify: The aspx files that handles the file upload.
Subscribe to:
Posts (Atom)