カスタムなエラーページ


ASP.NETでは内部で処理されない例外が発生した場合、カスタムなエラーページを出力することができる。


カスタムなエラーページを利用するには以下のようにWeb.ConfigのcustomErrorsタグに
エラーページのURIを指定するとよい。


web.config

<?xml version="1.0" encoding="UTF-8" ?>
<configuration>
  <system.web>
    <customErrors defaultRedirect="hogedir4/hogeError.html" mode="On" />
  </system.web>
</configuration>

ファイルの配置の例

ROOT
 |
 |---hogedir1
 |---hogedir2
 |---hogedir3
 |---hogedir4
 |     |---hogeError.html   ←カスタムなエラーページ
 | 
 |---web.config


なお、以下のように発生したエラー内容によって遷移先のエラーページを振り分けることもできる

<customErrors defaultRedirect="hogeError.html" mode="On">
  <error statusCode="403" redirect="hogeerr403.html" />
  <error statusCode="500" redirect="hogeerr500.html" />
</customErrors>


動作確認環境:Visual Stadio 2008