views:

418

answers:

2

I click on a link from one page that does a redirect to another page (Response.Redirect(page.aspx)).

The browser churns for about 30 seconds and the page displays. I'm trying to track down why it takes so long to load the page.

The page hosts two other custom controls.

I have commented out the lines of code for each and both controls, and the page still takes about 30 seconds to load.

I've set breakpoints on the Page_Load event for each of the controls as well as page.aspx and it also takes about 30 seconds from clicking the link with the Response.Redirect to the first break point.

I loaded up task manager and clicked on the link. I notice aspnet_wp.exe and csc.exe run during this 30 second time frame.

I'm wondering if there are some sort of code-behind shinanigans going on while I'm waiting for the page to load.

This only occurs the first time I click on the link. Afterwards, it's not as slow.

I've googled but there's not a lot of useful information about this. Anyone have any ideas?

Thanks,

---Dan---

A: 

The fact that csc.exe is running and it only occurs when you first click the link would suggest there are a lot of elements in the aspx that need to be compiled prior to displaying the page. Look for stuff that exists in expression holes <%= %>. It could also be something in the controls themselves (particularly if they are ascx user controls and not server controls).

The reason it only happens the first time you click on the link is because after that the compiled page object is cached, so there is no need to re-compile until your app is restarted.

ckramer
That may be. It's older, messy code that I didn't write. Of course I'm partial. I think you're right, but we have a lot of other code with a lot of other controls loading and none of them by far take as long as this one page.
Dan7el
+3  A: 

The very first time that the page is load, then the asp.net compile a lot of pages, almost every one found on the same dir, including modules, and dlls found on bin.

To speed up (your development) try use this option on web.config (only on your development computer).

<compilation batch="false" ... >

Using batch="false" asp.net compiles only one page, the one you are on it, so you get a big time the first time for the dlls, but after that, is a lot less if you have 200 pages, and you only change one, and you develop/debug only one.

Also if you can, try do not use App_Code directory, and place all your code inside a dll. Look more about compilation options on web.config to make it even run faster, change for example the temporary directory to a faster different disk than the C:.

Second trick

I will like to say one more trick that I found here on stackoverflow.

<compilation optimizeCompilations="true">

You only need to have install an ms patch http://support.microsoft.com/kb/961884 I have test it and the results are very good.

.net 4 and Visual studio 2010

The same think stands, but you do not need to run the patch.

Web Farm

I have notice that on web farm the first time that application is run, if you have many work on global.asax on application start, then I recoment to use Mutex and let only one pool make the compile of the pages ! Or else there are possibilities for conflicts and huge delay to start the application - especial if you use mutex on other part of the program.

Aristos
I believe that did it for the papge. Can you give me more details on what this setting does? It appears to solve the problem. Why is this a bad thing for a production environment?
Dan7el
This is not a bad thing. When you show your pages on public, you wish asp.net compiler, compile many pages, so the user can wait for the first one, but did not wait for the second page. On the other hand when you develop, many times you are only on one page and you try to fix this one page, and you do not care about to compile the other ones... There is a setting that say how many pages on the same directory you wish to compile every time.
Aristos