尝试完成网络流程,但是,我收到“请求超时”错误。我不知道我能做些什么来解决这个问题。
我修改了方法,为for循环中传递的每个数字创建一个新连接,但它似乎产生了相同的结果。
我更像是一名桌面开发人员,并不是非常精通ASP.Net,所以任何可以解决我问题的亮点都会很棒。
我已经查询了ASP后台工作者的信息,这似乎不是一个好方法,我已经增加了服务器设置以允许更高的超时,但是如果有大量的部件仍然会超时提供。
我还试图避免在服务器上安排执行提交的数字列表的单独进程。如果需要更多信息来理解这一点,请告诉我。
此外,当我尝试在本地运行应用程序(调试)时,只有当它放在实际站点上时才会出现问题。
以下是收到的确切错误:
Server Error in '/' Application.
Request timed out.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Web.HttpException: Request timed out.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[HttpException (0x80004005): Request timed out.]
以下是代码:
protected void btnSearch_Click(object sender, EventArgs e)
{
// Clear our reporting panel.
panelHolder.Controls.Clear();
// Store each line in a new array item.
string[] searchlines = txtboxSearch.Text.Replace("\n", "|").Split('|');
// Create a table row containing our main table headers.
panelHolder.Controls.Add(new LiteralControl("<table style=\"width:100%;\">" +
" <tr> " +
" <td></td> " +
" <td>Number</td> " +
" <td>Comparison</td> " +
" </tr>"));
// Variable to hold the row counts.
int j = 0;
// Store our current web members name for use in our tracking data.
string MemberName = Member.GetCurrentMember().Text;
// This table will be used solely for storing our excel exported data.
System.Data.DataTable dt = new System.Data.DataTable();
// Locate our part comparison results for every line of data supplied by our users.
for (int i = 0; i < searchlines.Count(); i++)
{
using (SqlConnection con = new SqlConnection(dbConnection))
{
// If this array item is not blank we will need to collect information about it.
if (searchlines[i].Trim() != string.Empty)
{
// Determine if data collection (reporting) is turned on.
Boolean isReporting = DataCollection();
using (SqlDataReader dr = Connect.ExecuteReader("SelectNumbers]", con,
new SqlParameter("@Number", searchlines[i].Trim()),
new SqlParameter("@CurrentMember", MemberName),
new SqlParameter("@DataCollection", isReporting)))
{
if (dr.HasRows)
{
while (dr.Read())
{
// Add our table rows containing our returned data set.
panelCompetitorHolder.Controls.Add(new LiteralControl("<tr><td>" + Convert.ToString(i + 1) + "</td>"));
AddTableData(dr, "Part Number");
AddTableData(dr, "Comparison");
// Go to our next line item.
j += 1;
}
}
}
}
}
}
// Add our table to the panel control.
panelHolder.Controls.Add(new LiteralControl("</table>"));
}
答案 0 :(得分:1)
您的问题可能在于IIS假定处理给定请求的最长时间。默认情况下,该值为90秒。您可以通过以下几种方式设置不同的时间:
通过 Web.config - 在web.config
文件中检查/添加此条目:
<system.web>
<httpRuntime executionTimeout="N" />
</system.web>
以编程方式 - 您可以将其添加到服务器端代码中:
Server.ScriptTimeout = N;
N
在两个选项中都是请求超时所需的秒数。
此外,如果服务器的applicationhost.config
或machine.config
文件中存在条目,您的值可能会被取代/忽略,如下所述:
http://www.iis.net/configreference/system.applicationhost/sites/sitedefaults/limits
如果是这种情况,您可能需要更改相应的条目 - 或者代替它,更改您的代码隐藏内容。