How can I achieve multi-lingual server errors in a

2019-05-15 05:07发布

问题:

My ASP.NET web application has the following section in web.config:

  <system.webServer>
    <httpErrors errorMode="Custom">
      <remove statusCode="500" subStatusCode="-1" />
      ...
      <error statusCode="500" prefixLanguageFilePath="httpErrors\custom" path="500.htm" responseMode="File" />
    ...
    </httpErrors>

My application directory contains the following files:

  • httpErrors\custom\en-US\500.htm
  • httpErrors\custom\de-DE\500.htm

These two files are identical except for their content language.

I now add a simple aspx file called errorsim.aspx to the root of my site to return a 500 status code for testing. Here are the contents:

<%@ Page Language="C#" %>
<script runat="server">
protected void Page_Init(object sender, EventArgs e)
{
    Response.Clear();
    Response.StatusCode = 500;
    Response.End(); 
}
</script>

When I browse to local.domain.com/errorsim.aspx from my local development machine (which is configured with en-GB globalisation settings) I see the 500.htm from the en-US directory which I assumed was therefore a default. However, after installing a Chrome extension to simulate requests from German localization culture, I'm still seeing the en-US content.

Am I doing something wrong here? Please note that I'm trying to handle errors statically without any .NET processing.