ASP.NETで処理に時間のかかるページで、Visual Studio デバッグ時は表示できるが IISのサーバーで実行するとHttpException エラーになる - ASP.NET

ASP.NETでページ表示処理に時間がかかるページで、Visual Studio デバッグ時は表示できるが IISのサーバーで実行するとHttpException エラーになる現象について紹介します。

現象

Visual Studioで、開発用のマシンでASP.NET アプリケーションをデバッグする際には、ページ表に長い処理時間がかかるページでも正しく表示できたにもかかわらず、IISの本番環境のサーバーに配置して動作させると、HttpException エラーが表示される場合があります。

エラー

イベントログに下記のエラーが表示されます。


Event Codeは"3001",イベントメッセージは "要求は中止されました。" のエラーとなります。
Exception typeは "HttpException", Exception messageは "要求がタイムアウトしました"が記録されます。
Event code: 3001 
Event message: 要求は中止されました。 
Event time: yyyy/MM/dd hh:mm:ss 
Event time (UTC): yyyy/MM/dd hh:mm:ss 
Event ID: (イベントID)
Event sequence: 20750 
Event occurrence: 1 
Event detail code: 0 
 
Application information: 
    Application domain: /LM/W3SVC/2/ROOT/document-1-131195190238858146 
    Trust level: Full 
    Application Virtual Path: (アプリケーションのパス) 
    Application Path: (アプリケーションの物理パス) 
    Machine name: ENGAWA 
 
Process information: 
    Process ID: 2992 
    Process name: w3wp.exe 
    Account name: IIS APPPOOL\(アプリケーションプール名) 
 
Exception information: 
    Exception type: HttpException 
    Exception message: 要求がタイムアウトしました

 
 
Request information: 
    Request URL: (リクエストURL) 
    Request path: (リクエストパス) 
    User host address: (IPアドレス) 
    User: (実行ユーザー) 
    Is authenticated: True 
    Authentication Type: Basic 
    Thread account name: IIS APPPOOL\(アプリケーションプール名) 
 
Thread information: 
    Thread ID: 43 
    Thread account name: IIS APPPOOL\(アプリケーションプール名)
    Is impersonating: False 
    Stack trace: 
 
 
Custom event details: 

原因

executionTimeout はデフォルト値が110秒のため、executionTimeout でタイムアウトしている可能性があります。

対処方法1:Webアプリ全体にexecutionTimeout を指定する場合

executionTimeout を指定します。
<httpRuntime executionTimeout="(タイムアウト秒数)" />
をweb.configに記述します。
記述場所は、system.webタグ内です。
web.configの例
<?xml version="1.0"?>
<configuration>
  <appSettings>
    ....
  </appSettings>

  <system.web>
    <!-- 
            デバッグ シンボルをコンパイルされたページに挿入するに
            は、compilation debug="true" に設定します。この設
            定はパフォーマンスに影響するため、開発時のみこの値
            を true に設定してください。
        -->
    <httpRuntime executionTimeout="600" />
    ...
  </system.web>
</configuration>

対処方法2:特定のページにexecutionTimeout を指定する場合

処理時間がかかるページがあらかじめわかっている場合は、特定のページにexecutionTimeoutを指定するほうが安全です。特定のページにexecutionTimeoutを指定する場合は、locationタグを利用します。
web.configの例
<?xml version="1.0"?>
<configuration>
  <appSettings>
    ....
  </appSettings>

  <system.web>
    <!-- 
            デバッグ シンボルをコンパイルされたページに挿入するに
            は、compilation debug="true" に設定します。この設
            定はパフォーマンスに影響するため、開発時のみこの値
            を true に設定してください。
        -->
    ...
  </system.web>
  <location path="longproc.aspx">
    <system.web>
      <httpRuntime executionTimeout="600" />
    </system.web>
  </location>
</configuration>
著者
iPentecのメインプログラマー
C#, ASP.NET の開発がメイン、少し前まではDelphiを愛用
最終更新日: 2024-01-06
作成日: 2016-09-28
iPentec all rights reserverd.