UTF-8 server encoding results in � characters on an ASP.NET site - asp.net

I am running an ASP.NET WebForms blog engine web site at maxpavlov.com
I am writing mostly in Russian on my blog. Sometimes, even though I am writing a perfectly normal Russian characters in, when I view the resulting rendered blog post page, I get some symbols substituted with �� characters.
I started digging. First, I have checked to see if a UTF-8 is set as a response encoding in the globalization section in web.config. It always was. Then I have noticed, that the pages my site generate don't have a <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> attibute provided in the page header. So I have added it to both masterpages (the display one, and the admin one - it is blogengine.net's specific stuff).
Now all pages that the web server generates have the charset value set to UTF-8, but the problem remains.
The site, when I create a blog post saves it to XML file, that also has an encoding set at the top of the XML file to UTF-8 with the following line:
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
Still, problem characters appear in the browsers, when I go to my site.
Where else should I fix this encoding problem?
More info: Fiddler tells me that the response header Content-Type: text/html; charset=utf-8
What is interesting, is that in different browsers, different characters in the HTTP Response get substituted with a �.

By the way, if anyone still wonders what the thing is - it's IIS Native RewriteModule. It's buggy even in version 2, if you disable it for the site, the problem goes away. Tried to report it in IIS.net - didn't believe me. Just learned to live without it on web sites that need to display a cyrillic characters.

Try using Windows-1251 (cyrillic) encoding for the russian alphabet.

Related

Who is setting the content-type response header for an ASP.NET application?

I have an ASP.NET WebForms application which displays chinese characters. The characters are not html encoded. The content-type of the html file is set to iso-8859-1 encoding but the content-type response header is set to utf-8 as you can see in the following screenshots:
I'm trying to find out who is setting the response header to utf-8. I couldn't find it in the code and it is also not configured in IIS.
Does anyone know how we can set it in code or if utf-8 is the default? If it was the default, why would it be not overriden by iso-8859-1 then?
I'm clueless at the moment.
Thank you in advance!

Firefox 84.0 is changing custom file extension from downloaded file

My web application creates a zip file to download files related to a "Task" instance. This zip file can contain images, .pdf or .txt files, the filename created has the form "{taskName}.taskBundle".
To download the file, the web application use the following headers in the response (from Firefox Network monitor):
Content-Disposition: attachment; filename="task1.taskBundle"
Content-Type: application/zip;charset=UTF-8
The problem:
Using Firefox 84.0 (Ubuntu and Windows versions), the browser is replacing the '.taskBundle' extension by '.zip', so the downloaded filename is "task1.zip" instead of "task1.taskBundle".
I tried to download the same file with Chrome (87.0) and another Firefox versions (83.0, 82.0, 80.0, 74.0) and the file name is correct: "task1.taskBundle".
Maybe should I add another header to the response to prevent Firefox change the file extension?
I can change the Content-Type to 'application/octet-stream' but the checkbox "Do this automatically for files like this from now on." is not displayed in the download dialog.
Additional notes:
My app is written using Grails 3.3.9 but I think it is not a Grails issue because the response headers are sent to the client as described before.
We're fixing this in https://bugzilla.mozilla.org/show_bug.cgi?id=1684183 , but it'll likely not be before Firefox 85 (ie we won't be shipping a security / out-of-cycle dot-release fix just to address this issue).
A simpler workaround for your usecase would be choosing / standardizing on a specific mimetype for these "task bundles", along the lines of application/x-my-fancy-application-task-bundle, if you don't want the UA to treat it as a zip file.
Both Firefox and other browsers can decide to act on the mimetype (e.g. in Firefox's case, we show "Open in Firefox" options if you send application/pdf or SVG mimetypes, even for Content-Disposition: attachment responses, to simplify opening the content immediately). Chrome has specific checks for application/zip when sniffing.
The regressing change here was part of a fix to handling web servers who send foo.jpg files with Content-Type: image/webp, where users complained that the resulting .jpg files were not, in fact, jpegs. So we added extension normalization for a number of different mimetypes. I mistakenly assumed that application/zip files would be, you know, zip files, and could be treated as such.
You might want to report this on Mozilla's Bugzilla site (https://bugzilla.mozilla.org) under Firefox as I can't find a report that describes this exact behavior. It looks like they've broken something in the latest version (whether it was a bug or a feature is hard to say) as I noticed this behavior on a site with a mismatching Content-Type too.
Of course, if it was an intentional change, it wouldn't be the first time the Mozilla has ignored web standards to do things "their way". It still annoys me to no end that I have to use the 5-slash hack to get file protocol links to open correctly when the standards clearly state otherwise (see: https://bugzilla.mozilla.org/show_bug.cgi?id=992123)

ASP.NET MVC - French/Spanish accent not correctly displayed

I'm working on multilingual website where I want to get language resource from SQL db table. Resource Table column is already set to nvarchar though It's completely strange behavior get junk character when it's getting rendered in MVC View.
û rendered as û
However, It's working fine in my local machine but problem occurs on production environment only. Don't know why!!!
Static & Resource file content of different languages are rendered perfectly fine but the problem occurs only for resources retrieved from SQL table.
Tried setting meta tag with utf-8 charset in page & globalization with request response encoding to utf-8 in web.config but couldn't resolve my problem.
Should it be problem of IIS or Entity Framework is converting it to junk characters? Really confused.....
I'm using MVC4 with Entity Framework.
Any help will be greatly appreciated.

Firefox 4 cannot load my ASP .Net site

I downloaded Firefox 4 yesterday and when I try to open my site (ASP .Net 2.0 site using masterpages) it tries to open the file rather than display the page. The message in the popup is: "You have chosen to open contactus.aspx which is a: aspx File from: 'my site'. What should Firefox do with this file?"
I am sending the following content-type: <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> I also tried changing the charset to utf-8, same thing.
When I try to run the page through the w3 validator it gives me this message:
Warning Character Encoding mismatch!
The character encoding specified in the HTTP header (utf-8) is different from the value in the <meta> element (iso-8859-1). I will use the value from the HTTP header (utf-8) for this validation.
Is the server (IIS) somehow setting the default charset? Could this mismatch be the problem? What else can I look for? Also, one more thing, I have a mobile site running on the same server which uses "application/xhtml+xml; charset=utf-8" as the content-type and it works fine in FF4. Thanks!
Edit: here is an example page from the site: http://www.cvps.com/jobs.aspx
Edit 2: I think I have narrowed down the problem to the mobile detection. I am using 51 degrees mobile device detection from http://51degrees.codeplex.com/
Specifying the content type in a meta tag won't help - the browser needs to answer the question of what type it is before it looks at the contents of the file. You need to specify the content type in the server config.
Encoding can be usefully specified in the meta tag, but I'd still prefer to have it right in the server config.
The problem turned out to be with the mobile detection framework I am using (51degrees.mobi). I found a post on their support forums here that was similar to my problem and was able to fix the problem.

html code doesn't run in the browser, and only display the code

in order to find the server spec. i've created a file in the root dir in my website called spec.htm and entered this content as i was offered by another user:
<html>
<head>
<title></title>
</head>
<body>
#ServerInfo.GetHtml()
</body>
</html>
but i only get a copy of the code in my browser and it doesn't run it,
what the problem might be?
EDIT: i think that the problem is that i'm not using IIS.
is there a way to do so without using IIS?
thanks
Please see the following article
http://www.asp.net/webmatrix/tutorials/14-introduction-to-debugging
The ServerInfo helper is a diagnostic tool that gives you an overview of information about the web server environment that hosts your page. It also shows you HTTP request information that is sent when a browser requests the page. The ServerInfo helper displays the current user identity, the type of browser that made the request, and so on. This kind of information can help you troubleshoot common issues.
Create a new web page named ServerInfo.cshtml.
At the end of the page, just before the closing tag, add the following highlighted code.
#ServerInfo.GetHtml()
Note, it appears as though this is designed to run in IIS only and not on Linux / Apache servers.
Note, this is a RAZOR syntax so your system needs to be able to run Razor by installing the WebMatrix
#ServerInfo.GetHtml() is a Razor view engine syntax. Try saving your file as .cshtml or .vbhtml
The problem is that your webserver is not set up to serve HTML files through the ASP.NET interpreter. Change the extension to .aspx (i.e., use the same code, but call it spec.aspx).
Are you setting the Content-Type header correctly. If not set to text/html or similar, the browser or framework may set the content-type to text/plain which will not render the html at all.
You can check this in Firebug in the Net tab, expanding the response that is associated with the page you are serving, and looking in the Headers tab. If the Content-Type header is anything besides text/html or text/xhtml, then you need to find a way to make your web server set that header properly
let me guess its just showing up "#ServerInfo.GetHtml()" on a webpage. This does nothing if you put it simply in a body tag of a html page. If you are running IIS make sure you are saving as .aspx and not .html
See "yourhtmlsource.com/myfirstsite/myfirstpage.html"
I hope I am understanding the question and this helps. I found it on the web page given above.
When you double-click a file on your computer’s desktop, the computer knows what program to open the file in by checking the file’s “extension”. A txt file will open in a text editor.
You need to give your document a file extension of ”.html”, which will tell it to open the file in your web browser, such as Internet Explorer, Firefox or Safari.
Right now you should be editing your HTML page in a text editor, which normally saves files with the extension “.txt”. We want to make it save in “.html”. In your text editor click File → Save As…. If you use Microsoft Windows, there will be a box labelled “save as type”; change it to “all files .”. This means that you can save the data (in this case, some text) into any format. Now type in the name index.html for your file and click save. Ex: file.txt becomes file.html.

Resources