Issues with Server.ScriptTimeout (and HttpContext.Current.Server.ScriptTimeout)

A

Anthony Williams

Hi all,

Am I right in thinking that if I set Server.ScriptTimeout to, say, 600 that
every request for an .ASPX page will wait up to 600 seconds before
responding with a "Request Timed Out" exception?

If I am right, then something screwy is going on with my server. Allow me to
explain.

I have a wee page that sends 30 emails out to various people in our company
using a mailserver which is on the same machine, and using the standard
System.Web.Mail classes.

It's taking around 2-3 seconds per email, and - as you can guess - when it
gets to emails 26 to 30, the ASPX page responds with a
System.Web.HttpException: Request Timed Out exception.

My solution is to grab the current value of Server.ScriptTimeout, reset
Server.ScriptTimeout to 600, and once the loop is finished (or on
Page.Error) it sets it back to the grabbed value.

Except it doesn't.

I've set it to 600 (Server.ScriptTimeout = 600 ' 10 Minutes) and started it
again.

No joy. Request timed out. Grr.

Is there something I'm not doing properly, or do I have to set the
ScriptTimeout somewhere else, or do I have to do it in the web.config file
or...

Help! Please!

Thanks,
Anthony
 
J

Jacob Yang [MSFT]

Hi Anthony,

Thank you for posting to the MSDN newsgroups.

There are a lot of possible reasons for the "Request Timed Out" exception.
Based on my research and experience, please try the following methods to
work around this issue on your side.

Method 1: Set the ExecutionTimeout Attribute Value in the Web.config File
1. Open the Web.config file in Notepad.
2. Add the httpRuntime element in the system.web section as follows:

<configuration>
<system.web>
<httpRuntime executionTimeout="90" maxRequestLength="4096"
useFullyQualifiedRedirectUrl="false"
minFreeThreads="8" minLocalRequestFreeThreads="4"
appRequestQueueLimit="100" />
</system.web>
</configuration>

3. Modify the value of the executionTimeout attribute to avoid time-out
errors.
4. Save the Web.config file.

Method 2: Set the ExecutionTimeout Attribute Value in the Machine.config
File
1. Open the Machine.config file in Notepad. The Machine.config file is
located in the
%SystemRoot%\Microsoft.NET\Framework\%VersionNumber%\CONFIG\ directory.
2. In the Machine.config file, locate the httpRuntime element. The
Web.config file is located in the Web Application directory

<httpRuntime executionTimeout="90" maxRequestLength="4096"
useFullyQualifiedRedirectUrl="false"
minFreeThreads="8" minLocalRequestFreeThreads="4"
appRequestQueueLimit="100" />

3. Modify the value of the executionTimeout attribute to avoid time-out
errors.
4. Save the Machine.config file.

If the above methods cannot resolve the problem, please do not "sets it
back to the grabbed value" and test this issue again.

I hope it helps.

Best regards,

Jacob Yang
Microsoft Online Partner Support
Get Secure! ¨C www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
A

Anthony Williams

Jacob,

Thank you for the reply. Unfortunately, none of your suggestions worked, and
I do not have access to the machine.config file on my hosting server.

Worth noting is that the machine.config suggestion didn't solve the problem
on my local machine.

I've tried setting the Server.ScriptTimeout value on the page and forcing a
second postback after the ScriptTimeout page was set, but still... no joy.

Any help would be great. Please though, I really need to be able to alter
the amount of time a page will spend on processing!

Cheers,
Anthony
 
J

Jacob Yang [MSFT]

Hi Anthony,

Based on my further research, it was found that there are two related
settings on this issue. One is the executionTimeout property in web.config
or in machine.config file; the other is the "ASP Script Timeout" property
in IIS. We should make sure both of the settings above should be set to an
appropriate value.

As for the "ASP Script Timeout" property in IIS, please follow the steps
below,

1.Open Internet Information Service manager.
2.Expand the appropriate nodes till the virtual directory where the ASP.NET
web app located.
3.Right click the virtual directory and select Properties.
4.Click the "Configuration¡­" and then switch to the Options tab.
5.Change the "ASP Script Timeout" property to an appropriate value.
6.Restart the IIS and try it again.

Please let me know if it helps.

Jacob Yang
Microsoft Online Partner Support
Get Secure! ¨C www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
A

Anthony Williams

Jacob,

Same again: System.Web.HttpException.

The web.config method has already failed for me, and it seems that this
method has also failed, and whilst I'd already tried the other IIS based
method you suggested, I'd always been under the impression that the "ASP
Script Timeout" value was for ASP pages, and not ASP.NET pages, as both are
handled by different processes.

I'm going to attempt to do a completely fresh install on a new box, and see
if the scripttimeout setting can be successfully be used on a new box.

Regards,
Anthony.
 
J

Jacob Yang [MSFT]

Hi Anthony,

Thank you for your update.

Is it possible for you to show a simple testing sample code here and tell
me how to reproduce the problem step by step on my side? It will be very
helpful to the trouble shooting. I certainly appreciate your time.

Best regards,

Jacob Yang
Microsoft Online Partner Support
Get Secure! ¨C www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
A

Anthony Williams

Jacob,

Since I've re-written the code, and my only backup of the old code is on a
SourceSafe server which is currently unavailable to me, I'll have to do it
from memory.

Basically, we had code retrieving around 34 records from a database, looping
through each of them, sending an email, and then returning to the page.

Our outgoing email server insists on performing an MX lookup on all domains
and checking to see if the target email address exists - this takes around
3 to 4 seconds per request - and this is why we need to increase the
timeout.

On our development server and production server we're using Merak Mail
Server which appears to insist on doing the MX Lookup, but also appears to
do it synchronously - a pain for us in this respect.

As mentioned, I've already re-written the code using asynchronous calls and
delegates, but I'd really like to know why Server.ScriptTimeout is not
apparently working.

So...

' --- CODE BEGINS ---

Imports System
Imports System.Data.SqlClient
Imports System.Web.Mail

Public Class MailTest

Private Sub Page_Load(ByVal sender As Object, _
ByVal e As EventArgs) Handles MyBase.Load

Server.ScriptTimeout = 180
StartNewTest()

End Sub

Private Sub StartNewTest

Dim cmd As New SqlCommand("ERTGetRecipients")
cmd.CommandType = CommandType.StoredProcedure
cmd.Connection = New SqlConnection( _
ConfigurationSettings.AppSettings("ConnectionString"))

Dim da As New SqlDataAdapter(cmd)
Dim ds As New DataSet
da.Fill(ds)
da.Dispose()
cmd.Connection.Dispose()
cmd.Dispose()

For Each dr As DataRow In ds

Dim msg As New MailMessage
msg.To = "..."
' ...
' other code here
' ...

SmtpMail.Send(msg)

Next

End Sub

End Class

' --- CODE ENDS ---

Your help is much appreciated!

Regards,
Anthony
 
J

Jacob Yang [MSFT]

Hi Anthony,

Thank you for your update.

As I understand, you have found a workaround for this issue. Now your
concern is that why the Server.ScriptTimeout is not apparently working.

As I have mentioned before, there are a lot of possible reasons for the
"Request Timed Out" exception. The Server.ScriptTimeout does not work here
because it is not the root cause of this specific problem. Thank you for
your understanding.

I have found an example of how the Server.ScriptTimeout works. Please refer
to the following Knowledge Base article.

PRB: Response.WriteFile Cannot Download a Large File
http://support.microsoft.com/default.aspx?scid=kb;en-us;812406

The workaround in the above article works fine when set debug = "true" in
the web.config file. But when set debug = "false" in the web.config file,
the downloading cannot be finished. The follows are the reproducing steps:

1. Setup a Windows XP Pro machine with VS.NET 2003.

2. Create a default C# web application.

3. Add a button to the web form and add the C# work around downloading code
to the button click event handler.

4. Change the ¡°DownloadFileName¡± to a large file (200M).

5. Set debug = "false" in the web.config file.

6. Change to the release mode and rebuild the solution.

7. On another Windows XP Pro machine (client), access the web form and
click the button to download the large file.

8. The client will not get the entire file. (Only about 80M is downloaded.)

The solution is using the Server.ScriptTimeout.
...
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
Server.ScriptTimeout = 360;
}
...

I hope it helps.

Best regards,

Jacob Yang
Microsoft Online Partner Support
Get Secure! ¨C www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top