serving text/HTML content to chrome in asp.net shows page text - html

I dynamically generate an html page in an .aspx file like this:
Response.Clear()
Response.ClearContent()
Response.ClearHeaders()
Response.Buffer = True
Response.ContentType = "text/HTML"
Response.AddHeader("Content-Disposition", "inline")
Response.OutputStream.Write(FilledBuffer, 0, FilledBuffer.Length)
Response.OutputStream.Flush()
Response.OutputStream.Close()
Response.End()
where FilledBuffer (a byte array) is valid html like:
<!DOCTYPE html>
<html>
<head>
<title>My Page</title>
</head>
<body>
<div>content</div>
</body>
</html>
When I view this in IE8+ it renders an as html page, however in Chrome it displays the html as text. My first thought is the MIME type but text/HTML is correct for html, so I am at a loss.
I must be missing something very simple here...or the internet would not work...
In fiddler the request between a standard aspx page that renders html and the above non-working page are identical, specifically:
GET http://localhost:1202/test.aspx HTTP/1.1
Host: localhost:1202
Connection: keep-alive
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.112 Safari/537.36
Referer: http://localhost:1202/Mypage.aspx
Accept-Encoding: gzip, deflate, sdch
Accept-Language: en-US,en;q=0.8

The byte array used by the response stream was created with unicode encoding, thus the output was indeed unicode. Interesting that IE does not seem to care about this but Chrome recognized this was not html and simply rendered the page as text. The giveaway unicode double charter width was not displayed by Chrome and inspecting page source showed a perfectly valid looking html file. It was not until inspection in fiddler that the unicode was detected which lead to the discovery of the incorrect conversion.

Related

Requesting css style as text/css get response as text/html?

Basically I have:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="main.css"/>
by doing this I get a console error saying: main.css was not loaded because its MIME type, “text/html”, is not “text/css”.
through sniffing my browser network tab, It appears that the request is made as text/css but the response comes as text/html.
Request Headers (0.361 KB):
User-Agent: "Mozilla/5.0 (X11; linux x86_64; rv:52.0) gecko/20100101"
Accept: "text/css,*/*;q=0.1"
Accept-language: "en-US, e;q=0.5"
Accept-Encoding: "gzip, deflate"
Response Header (0.123 KB):
Content-Type: "text/html;charset=ISO-8859-1"
Date:"FRI 20 Oct 2017 ..."
Transfer-Encoding: "chunked"
FYI: This stylesheet is request in mutiple pages, at the other pages it works but not here.
Much regards

HTML5 video playback fails in IE (or: Missing range request)

I apologise for asking a question asked ten thousand times on SO before. This situation seems different from the others. In short, video playback via always works on Firefox and Chrome but always fails in Internet Explorer, all versions, all Windows versions.
I have a web page set up according to Microsoft's HTML5 suggestions. A modal window supplies the video:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
</head>
<body>
<div class="popupwindow">
<video controls autoplay preload="auto" style="width:100%">
<source src="streamvideo.rails?file=$fileName" type="video/mp4" />
</video>
</div>
</body>
</html>
streamvideo.rails is a Castle Monorail C# function that acquires a video file in a cloud server as a Stream and streams it back as a range request.
First off, I'm sure it's not the usual problems: the codec is probably OK, the response's Content-Type is right (video/mp4) and IE is even picking up the video correctly, at least initially. The in-browser network sniffer shows it received a small chunk of an MP4 file and then stopped.
One oddity I noticed: IE is not framing the video request as a range request whilst Chrome/FF are. Chrome's headers:
GET [my URL]?fileName=e65b0b0d-0911-4e3f-bc71-7b5d5a65db57.mp4 HTTP/1.1
Host: localhost
Connection: keep-alive
Accept-Encoding: identity;q=1, *;q=0
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.143 Safari/537.36
Accept: */*
DNT: 1
Accept-Language: en-US,en;q=0.8
Range: bytes=0-6130
IE's headers:
GET [same URL] HTTP/1.1
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko
Accept: */*
GetContentFeatures.DLNA.ORG: 1
Pragma: getIfoFileURI.dlna.org
Accept-Language: en-US
Accept-Encoding: gzip, deflate
Connection: Keep-Alive
DNT: 1
Host: localhost
I speculate that if I fix this discrepancy, the problem will go away. So: why is IE deciding not to make a range request? How can I force it to? If you think I'm chasing a bogus clue, what else can I check?
This is a little late for a response. Just thought if somebody searches this, my answer would help them. What I found is that when IE requests the video content the "Accept-Ranges: Bytes" header is not present as with Firefox and Chrome, thus on first request set the response as follows (This is an ASP.Net Core example):
response.Headers.Add("Accept-Ranges", "bytes");
response.ContentLength = [length of actual video file];
response.StatusCode = (int)HttpStatusCode.OK;
response.ContentType = [ContentType of requested content];
When the response hits the browser again it will evaluate the headers and setup the video control as well as the next request with the correct headers. Now when you validate for the existence of the Range header it will be there and the code to stream will work as normal.
Hope this helps, it worked for me.
Elaborating on Jean Roux's response:
HTML5 video streaming is supported via range requests and responses. MDN has a good introduction: https://developer.mozilla.org/en-US/docs/Web/HTTP/Range_requests
IE10 and IE11 on W7 and W8 do NOT make range requests (there is no Range header). Per the RFC, the server may respond with a 200 response and the entire file contents. But doing so will cause IE to not play the file (I'm not sure why, but based on the network tab in dev tools, the content is truncated, e.g. server sent ~10MB but IE was only looking at the first few KB). I had to rejigger my server so that I respond with a 206, the entire file contents, and Accept-Ranges and Content-Range headers.
BTW: you asked this before W10 was released. Both Edge and IE11 on W10 DO make the range requests.
I'm having the same issue with Chrome on Android. The range header is missing. For Internet Explorer I did something like this:
$http_range = (isset($_SERVER["HTTP_RANGE"])) ? $_SERVER["HTTP_RANGE"] : "bytes-0";
Thats in my PHP script that serves the video/mp4 data. All it does is check if the range header is set, if not, it will assume that the start of the file has been requested. Internet Explorer seems to be smart enough to then take over if the user seeks to a different part of the video, i.e. generates the required range header.
Works great in IE... however, I tried the above in Chrome and it's still not happy :((
I had the same problem.
MIME was set correctly. It was video/mp4.
I checked apache config. It supported video/mp4 and audio/mp4.
The video was encoded by H.264.
I could see the video in chrome, not in IE( from 9, 10, 11 ).
I changed the video size from 1920 x 1280 to 720 x 720 and encoded.
And it worked magically.
Now I'm searching why it worked by changing the video's width and height.

Trying to keep it unicode all the way

Arabic user data that was submitted from a website form occasionally ends up Mojibake in our database. A user would type something like:
الإعلان العالمى لحقوق الإنسان
in an input form and the post is received by a server and stored in a database. When we retrieve the message from the database, it reads:
الإعلان العالمى لحقوق الإنسان
The form is in an embedded iframe page with these tags:
<!DOCTYPE HTML>
<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="content-type" />
<!-- other header elements -->
</head>
<body>
<form accept-charset="utf-8" action="https://www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8" method="post">
<!-- other body elements -->
</body>
</html>
A post generate these request headers
Accept */*
Accept-Encoding gzip, deflate
Accept-Language en-US,en;q=0.5
Cache-Control no-cache
Connection keep-alive
Content-Length 543
Content-Type application/x-www-form-urlencoded; charset=UTF-8
Host www.salesforce.com
Origin [ -- redacted -- ]
Pragma no-cache
Referer [ -- redacted -- ]
User-Agent Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:28.0) Gecko/20100101 Firefox/28.0 FirePHP/0.7.4
x-insight activate
And receives these response headers
HTTP/1.1 200 OK
Date: Fri, 25 Apr 2014 09:15:49 GMT
Cache-Control: private
Content-Type: text/html;charset=UTF-8
Transfer-Encoding: chunked
I have no control over the server configuration of the machine serving the form or the server processing the form data.
Is there anything more I can do in the page markup that can prevent the problem? Are there known user agents which would ignore the accept-charset attribute?
Since the character scramble only happens occasionally, what is the best way to try and replicate / isolate the problem?
Thanks!

Website is displayed as HTML-Code instead of rendered HTML - indeterministic

I have a problem with a website, where sometimes only the HTML text is displayed in the browser window, instead of the rendered HTML page. This happens sometimes in all browsers.
Example URL:
http://www.starkl.at/view/p-1258/Newsletter---Gartentipp/
The HTTP request headers from IE9 are (Cookies are not shown):
GET http://www.starkl.at/view/p-1258/Newsletter---Gartentipp/ HTTP/1.1
Accept: text/html, application/xhtml+xml, */*
Referer: http://www.starkl.at/view/p-1931/Service/
Accept-Language: de-AT
User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)
Accept-Encoding: gzip, deflate
Connection: Keep-Alive
DNT: 1
Host: www.starkl.at
Pragma: no-cache
The HTTP response headers are:
HTTP/1.1 200 OK
Date: Wed, 19 Sep 2012 07:43:49 GMT
Cache-Control: no-cache, no-store, must-revalidate, proxy-revalidate
Content-Type: text/html;charset=UTF-8
Content-Length: 21160
Keep-Alive: timeout=15, max=100
Connection: Keep-Alive
Also the content length (in bytes) seems to match.
It's a Java 6/7 application running on a Tomcat 6/7, with an additional httpd 2.2.x in front.
Any idea what the problem could be????
Thanks in advance!
If the browser writes the code and not renders it is because it's being told to do so, probably your app is returning html encoded in a way that browser thinks it's plain text.
Open tools, options, email, email options, then uncheck "Read all standard mail in plain text." This is for Outlook 2003 so your version, if not 2003, might be slightly different.

Getting latin1 instead of UTF-8 with CGI::Application

I am using CGI::Application with UTF-8 data.
In the HTML have I set encoding to UTF-8 like so
<!DOCTYPE html>
<html dir="ltr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
but the output is treated as latin1, as special characters are displayed as 2 characters.
Page Info in Firefox says the page is encoded with ISO-8859-1 despite the HTML header.
I have only been able to find these two posts about the problem, but they are old and very complicated.
Anyone that have solved this problem?
Update: Here are the HTTP header from FireBug.
Response Headers
Date Tue, 26 Apr 2011 09:53:24 GMT
Server Apache/2.2.3 (CentOS)
Connection close
Transfer-Encoding chunked
Content-Type text/html; charset=ISO-8859-1
Request Headers
Host example.com
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:2.0) Gecko/20100101 Firefox/4.0
Accept text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language en-gb,en;q=0.5
Accept-Encoding gzip, deflate
Accept-Charset ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive 115
Connection keep-alive
I noticed that if I force UTF-8 by FireFox->Web Developer->Character Encoding->Unicode (UTF-8), if looks correct.
Your HTTP headers:
Content-Type text/html; charset=ISO-8859-1
… claim the document is encoded as Latin 1. Real HTTP headers take priority over HTML <meta> data.
$webapp->header_add(-type => 'text/html; charset=UTF-8');
… should do the job if I'm reading the documentation correctly.