500 - 请求超时

Blo*_*ops 10 c# asp.net azure

我有一个运行大约4分30秒的脚本,我已经在我的aspx网页的配置页面中将默认超时时间更改为3600秒

它没有返回500 - IIS 8上的开发版本和上载版本的请求超时错误.

但是,当我将它上传到azure的实时站点时,它返回500 - 请求超时错误.

Azure是否会覆盖这些设置?

CONFIGS:

<configuration>
  <system.web>
    <httpRuntime executionTimeout="3600" />
    <sessionState timeout="360" />
    <compilation debug="false" targetFramework="4.0">
      <assemblies>
        <add assembly="System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
        <add assembly="System.Web.Extensions.Design, Version=4.0.0.0, Culture=neutral/>
      </assemblies>
    </compilation>
  </system.web>
</configuration>
Run Code Online (Sandbox Code Playgroud)

编辑:

我将SCM_COMMAND_IDLE_TIMEOUT添加到具有3600值的azure应用程序设置中,但它没有修复错误,现在尝试提高我的代码性能:

原版的:

Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();

Dictionary<int, Dictionary<DateTime, float>> d_PhoneNo_DateDataList = new Dictionary<int, Dictionary<DateTime, float>>();

string sqlcommand = "SELECT ---- FROM ---- INNER JOIN ---- ON ---- = ---- WHERE PhoneNo=@PhoneNo AND date BETWEEN @Date1 AND @Date2";
string strConnectionString = ConfigurationManager.ConnectionStrings["---"].ConnectionString;

using (SqlConnection conn = new SqlConnection(strConnectionString))
{
    Dictionary<DateTime, float> d_DateTime_Data;

    using (SqlCommand cmd = new SqlCommand(sqlcommand, conn))
    {
        cmd.Parameters.Add("@PhoneNo", SqlDbType.Int);
        cmd.Parameters.AddWithValue("@Date1", dateStart);
        cmd.Parameters.AddWithValue("@Date2", dateEnd.AddDays(1));
        conn.Open();

        for (int i = 0; i < phoneNo.Count; i++)
        {
            d_DateTime_Data = new Dictionary<DateTime, float>();
            cmd.Parameters["@PhoneNo"].Value = phoneNo[i];
            cmd.ExecuteNonQuery();
            using (SqlDataReader reader = cmd.ExecuteReader())
            {
                while (reader.Read())
                {
                    d_DateTime_Data.Add(DateTime.Parse(reader["Date"].ToString()), float.Parse(reader["Data"].ToString()));
                }
            }
            d_PhoneNo_DateDataList.Add(phoneNo[i], d_DateTime_Data);
        }
        conn.Close();
    }
}
Run Code Online (Sandbox Code Playgroud)

我试图在Parallel.For中使用concurrentDictionary,但它会导致DataReader出现问题

ConcurrentDictionary<int, Dictionary<DateTime, float>> d_PhoneNo_DateDataList = new ConcurrentDictionary<int, Dictionary<DateTime, float>>();

string sqlcommand = "SELECT ---- FROM ---- INNER JOIN ---- ON ---- = ---- WHERE PhoneNo=@PhoneNo AND date BETWEEN @Date1 AND @Date2";
string strConnectionString = ConfigurationManager.ConnectionStrings["----"].ConnectionString;

using (SqlConnection conn = new SqlConnection(strConnectionString))
{
    Dictionary<DateTime, float> d_DateTime_Data;

    using (SqlCommand cmd = new SqlCommand(sqlcommand, conn))
    {
        cmd.Parameters.Add("@PhoneNo", SqlDbType.Int);
        cmd.Parameters.AddWithValue("@Date1", dateStart);
        cmd.Parameters.AddWithValue("@Date2", dateEnd.AddDays(1));
        conn.Open();

        Parallel.For(0, phoneNo.Count, (index) =>
        {
            d_DateTime_Data = new Dictionary<DateTime, float>();
            cmd.Parameters["@PhoneNo"].Value = phoneNo[index];
            cmd.ExecuteNonQuery();
            using (SqlDataReader reader = cmd.ExecuteReader())
            {
                while (reader.Read())
                {
                    d_DateTime_Data.Add(DateTime.Parse(reader["Date"].ToString()), float.Parse(reader["Data"].ToString()));
                }
            }
            d_PhoneNo_DateDataList.TryAdd(phoneNo[index], d_DateTime_Data);
        });
        conn.Close();
    }
}
Run Code Online (Sandbox Code Playgroud)

Hai*_*dad 11

如果您的Web应用程序包含需要很长时间的任何代码,那么请将其移至Web作业,至少避免对应用程序可伸缩性产生任何影响.

1-创建Web作业并移动需要很长时间的代码.

2-使Web作业侦听队列

3-在Web应用程序中,用户提交后,在队列中插入包含所需详细信息的消息

4-如果您需要通知用户有关该过程的完成情况,请使用SignalR,从您的JavaScript连接到集线器,并在Web作业代码中发布消息,这将立即通知用户


evi*_*obu 8

您最有可能遇到App Service中硬编码的230秒超时.

有关更多信息,请参阅此问题:
Azure ASP .net WebApp请求超时

尝试将长时间运行的任务作为WebJob,并将结果发布到队列或表.或者发布到Table/Blob(如果您重复使用数据,甚至可能是Redis)并使用Queue消息发送信号.