Answered by:
Exception errors cause garbled text

Question
-
User-195907812 posted
Hi,
I have a live webforms project and I noticed a strange issue today when the database went down.When an exception occurs, the page is returned as follows:
https://i.imgur.com/VfpzxHd.jpg
I have created a test page to manually invoke an exception, and issue is still there.
I've added the following to my webconfig, but it doesn't work:
<customErrors mode="On" redirectMode="ResponseRewrite" defaultRedirect="/uk/error_deleteme" />
Does anyone know why this is happening?Wednesday, January 24, 2018 3:16 PM
Answers
-
User-1838255255 posted
Hi RageRiot,
According to your description and error message, I found someone who meet the similar issue as you, please check the solutions:
Page displays random symbols instead of error message on Firefox:
ASP.NET GZip Encoding Caveats:
https://weblog.west-wind.com/posts/2011/May/02/ASPNET-GZip-Encoding-Caveats?Page=2
Best Regards,
Eric Du- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, January 25, 2018 9:55 AM
All replies
-
User753101303 posted
Hi,
The error is supposed to be shown using which language? This character is used when values are not matching a valid unicode characters but even other characters are looking weird.
If you are using a latin language I suspect it could be that you have an exception handler somewhere (when the db fails ?) that uses Response.Write to show binary data when an error happens ???
Wednesday, January 24, 2018 4:03 PM -
User-195907812 posted
Hi PatriceSc,
Any errors should be shown in English.
If I view the source it's all garbled too.Wednesday, January 24, 2018 4:10 PM -
User753101303 posted
And in the browser or by using F12 the page encoding is ?
For now it seems really something like rendering binary data as text making mosft of them being randomly invalid ???
Wednesday, January 24, 2018 4:22 PM -
-
User753101303 posted
Sorry, more precisely I meant F12 Network, Response headers and looking at the "Content-Type" to see if you have something such as : text/html; charset=utf-8
Edit: I confirm that random bytes are producing a similar result. For some reason it seems binary content is rendered from the server side when an exception happens ???
Wednesday, January 24, 2018 5:01 PM -
User-37275327 posted
Check this thread, But not sure your environment is same as facts on the thread.
Wednesday, January 24, 2018 5:09 PM -
User-195907812 posted
I've just tried this on a different computer (same source version), and I get the correct error:
Looking at that thread, I think it might have something to do with compression.
I added this a long time ago to Global.asax.cs:void Application_BeginRequest(object sender, EventArgs e)
{
// Implement HTTP compression
HttpApplication app = (HttpApplication)sender;// Retrieve accepted encodings
string encodings = app.Request.Headers.Get("Accept-Encoding");
if (encodings != null)
{
// Check the browser accepts deflate or gzip (deflate takes preference)
encodings = encodings.ToLower();
if (encodings.Contains("deflate"))
{
app.Response.Filter = new DeflateStream(app.Response.Filter, CompressionMode.Compress);
app.Response.AppendHeader("Content-Encoding", "deflate");
}
else if (encodings.Contains("gzip"))
{
app.Response.Filter = new GZipStream(app.Response.Filter, CompressionMode.Compress);
app.Response.AppendHeader("Content-Encoding", "gzip");
}
}
}Wednesday, January 24, 2018 6:17 PM -
User-195907812 posted
Ok, so I've had a chance to re-test.
If I comment out the Application_BeginRequest method it works.
Is there another/better way of compressing my (webforms) site?Thursday, January 25, 2018 9:44 AM -
User-1838255255 posted
Hi RageRiot,
According to your description and error message, I found someone who meet the similar issue as you, please check the solutions:
Page displays random symbols instead of error message on Firefox:
ASP.NET GZip Encoding Caveats:
https://weblog.west-wind.com/posts/2011/May/02/ASPNET-GZip-Encoding-Caveats?Page=2
Best Regards,
Eric Du- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, January 25, 2018 9:55 AM -
User-195907812 posted
Perfect, thanks.
Adding...
protected void Application_Error(object sender, EventArgs e)
{
Response.Filter = null;
}
To the Global.asax.cs worked :)
Thursday, January 25, 2018 10:05 AM