Ignorar y borrar un error si su Exception.Message contiene algo en ASP.Net AJAX

I want to write some configuration in web.config file, that will make my ASP.Net app ignore/clear any uncaught exceptions, when Exception.Message for these exceptions contains 'This is an invalid webresource request'. Is this possible using web.config only? I know I can do this in Application_Error event code, but I was looking for a codeless approach.

Also, I am using ELMAH for error handling, and the app runs in IIS 7.

preguntado el 01 de julio de 12 a las 17:07

I do not think you can do that using just the web.config fuera de la caja. Why do you want to avoid using code in the global.asax ¿¿expediente?? -

The app is pre-compiled, so I will need to re-compile the app and publish changes if I make a code-change in global.asax. That is my only concern with code changes. With web.config approach, I do not need to re-compile, and its very easy to move web.config to production. -

1 Respuestas

No such web.config elements exist to do that. I reccommend against using Web Site applications, the Web Application Project type creates a single assembly and if all you do is change code in global.asax.cs and not any markup, all you need to do is copy over the single assembly.

In global.asax.cs you can use the Application_Error handler to catch unhandled exceptions, log them if desired, and clear the error. Example:

 protected void Application_Error(object sender, EventArgs e)
            Exception ex = Server.GetLastError().GetBaseException();
            if(!ex.Message.Contains("File does not"))


Respondido 01 Jul 12, 23:07

Peter-By using your approach, I am finding that the page is suddenly becoming blank, as soon as the Server.ClearError() is called. Any ideas why this is happening? - Sunil

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.