CustomErrors with redirectMode = "ResponseRewrite" do not work on shared hosting

I am trying to customize my own error pages for my site (ASP.NET 4, integrated pipeline).

Everything works correctly on the local computer, but custom error pages for .aspx pages do not appear on shared hosting (I see error pages by default).

If I change redirectMode="ResponseRewrite" to redirectMode="ResponseRedirect" , everything works correctly on the local and shared machine.

error.aspx is the real file, which is located next to the web.config (in the root directory of the site). The site does not have a Global.asax file.

The local computer runs IIS 7.5, I do not use routing (at least consciously), and shared hosting reports that Server: Microsoft-IIS/7.5 X-AspNet-Version: 4.0.30319

Could you tell me what could be causing such different behaviors and what I must do to solve the problem.

Here is an excerpt from my web.config :

 <system.webServer> <httpErrors errorMode="Custom"> <remove statusCode="404" /> <error statusCode="404" path="/error.aspx" responseMode="ExecuteURL" /> </httpErrors> </system.webServer> <system.web> <customErrors mode="On" defaultRedirect="error.aspx" redirectMode="ResponseRewrite"> <error statusCode="404" redirect="~/error.aspx"/> </customErrors> <httpRuntime requestValidationMode="2.0" /> </system.web> 
+4
source share
2 answers

After discussion with the hosting provider, it turned out that:

  • my approach is beautiful
  • but it will not work as expected because the hosting provider has disabled this feature through machine.config .

So, never underestimate the number of providers.

+2
source

I have the following comment in my web.config:

for IIS 7.5, use errorMode = "Custom"; use responseMode = "ExecuteURL" when using routing, otherwise use responseMode = "Redirect"

Just do not ask me to explain, because I do not know! I just sorted it out with trial and error.

+1
source

All Articles