0

In my web.config, I don't have anything like CustomErrors. As I want everything to be handled by Global.asax .

This is my web.config:

<?xml version="1.0"?>

<configuration>
  <system.web>
    <compilation targetFramework="4.5" debug="false"/>
    <authentication mode="Forms" >
      <forms loginUrl="login.aspx" name=".ASPNETAUTH" protection="None" path="/" timeout="20" >
      </forms>
    </authentication>

    <httpRuntime requestPathInvalidCharacters="&lt;,&gt;,:,\,?" targetFramework="4.5" maxRequestLength="1048576"/>

    <httpModules>
      <add name="ImageResizingModule" type="ImageResizer.InterceptModule"/>
    </httpModules>

  </system.web>

  <system.webServer>

    <validation validateIntegratedModeConfiguration="false"/>

    <modules>
  <add name="FormsAuthenticationModule" type="System.Web.Security.FormsAuthenticationModule"/>
  <remove name="UrlAuthorization"/>
  <add name="UrlAuthorization" type="System.Web.Security.UrlAuthorizationModule"/>
  <add name="ImageResizingModule" type="ImageResizer.InterceptModule"/>
</modules>
    <security>
      <requestFiltering allowDoubleEscaping="true">

      </requestFiltering>
    </security>

  </system.webServer>

</configuration>

And this is Application_Error event in Global.asax :

void Application_Error(object sender, EventArgs e)
{
    try
    {
        Response.Redirect("~/error.html");
    }
    catch
    {
    }
}

Do I need web.config?

Mike
  • 219
  • 3
  • 10
  • Note that `HttpResponseException`s are ignored by `ApiExceptionHandler` and derived classes [by design](https://learn.microsoft.com/en-us/aspnet/web-api/overview/error-handling/exception-handling) and will never result in `Application_Error` firing. – user1007074 May 02 '23 at 15:50

1 Answers1

0

I would recommend using a CustomErrors section in your web.config to accomplish this.

Maybe also have a look here: Is global.asax Application_Error event not fired if custom errors are turned on?

For example, you could try adding this to your web.config. Note, I didn't test it, but just copied it together from the mentioned post:

<customErrors defaultRedirect="~/error.html" mode="RemoteOnly">
</customErrors>

There is actually a very good blog article on that topic and the options you have: http://www.codeguru.com/csharp/.net/net_debugging/article.php/c19411/Web-Application-Error-Handling-in-ASPNET.htm

From what I gathered in the above (and related) articles, I would almost guess, you need a call to Server.ClearError in your Application_Error, or the error will bubble up to the web.config error handling, which by default will display a friendly error message when the application is viewed from remote. (value is "RemoteOnly").

Community
  • 1
  • 1
Swiss Dev
  • 1
  • 3
  • I can't say for sure without trying it out myself, but considering the article I posted above, I'd say you'll have to explicitely turn off CustomErrors in order to receive full control over the error-behaviour. I would give this a try. – Swiss Dev Aug 04 '15 at 14:28
  • 1
    I've just come across a good article on the topic, added the link in the post above. – Swiss Dev Aug 04 '15 at 14:36