In my application site I have a controller action creating and generating an Excel file: from a list of items, it writes every field of every item through a for cycle.
Simplified example (coz I have ~30 fields):
String az = "";
az = az + "<table border=\"1\">";
az = az + "<tr>";
az = az + "<th>Field 1</th>";
az = az + "<th>Field 2</th>";
for (int i = 0; i < items.Count(); i++){
az = az + "<tr>";
az = az + "<td>" + items.ElementAt(i).Field1+ "</td>";
az = az + "<td>" + items.ElementAt(i).Field2+ "</td>";
az = az + "</tr>";
}
az = az + "</table>";
Now, when I have a few rows, no problem.
When I have a large number of rows, it takes a while generating the file. This is not a problem on localhost, but after I publish the site on IIS it takes until 7x(the time).
Example:
Loading 250 rows: 0,8s on localhost, 4s on IIS
Loading 615 rows: 4s on localhost, 21s on IIS
Loading 950 rows: 7s on localhost, 38s on IIS
Loading 1300 rows: 15s on localhost, 104s on IIS
Does anyone know what the problem is? Do I have to change/set some variable on the IIS site? In case I haven’t to, is there a way to optimize the performance on IIS?
Thanks, hope someone can help me!
First off if you have to build your html like this then at least use a string builder
However, it might well be worthwhile to reconsider this approach entirely and look at using a Razor view instead of compiling your html. Of course this depends on other considerations you might have.