默认响应内容类型有问题
我有一个具有以下文档类型的网站:
<!DOCTYPE HTML>
<html>...</htm>
我发现了一个导致某些移动浏览器崩溃的问题(黑莓和旧版机器人)。例如,在 Android 上,当发出请求时,它会发送以下标头:
Accept: application/xml,appliation/xhtml+xml,text/html ...
问题是我的网站不符合 XHTML,但 IIS 决定,由于请求页面的浏览器更喜欢 xhtml,因此它应该提供该标头,而不是 文本/html
。
我尝试通过将 添加到页面来覆盖它,但它没有不工作。
我正在尝试找出告诉 iis 停止为 http://mydomain.com/mobile
的所有请求提供 xhtml 服务的最简单方法。我正在考虑通过覆盖 HttpModule 中的 Response.Content-Type 来实现这一点。
我在这里缺少什么吗?修复它的最佳方法是什么?
I have a website that has the following Doctype:
<!DOCTYPE HTML>
<html>...</htm>
I discovered an issue causing certain mobile browsers to break (blackberries and older androids). On the Android for instance, when a request is made it sends this header:
Accept: application/xml,appliation/xhtml+xml,text/html ...
The problem is that my site doesn't conform to XHTML but IIS decides that since the browser requesting the page prefers xhtml then it should serve that instead of text/html
.
I've tried overriding it by adding <META HTTP-EQUIV="CONTENT-TYPE" CONTENT="text/html; charset=UTF-8">
to the page, but it doesn't work.
I'm trying to figure out the easiest way to tell iis to stop serving xhtml for all requests to http://mydomain.com/mobile
. I was thinking of doing it by overwriting the Response.Content-Type in an HttpModule.
Is there anything I'm missing here? What's the best way to fix it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
IIS 没有您提到的功能(覆盖 .NET 输出的内容类型),因为这取决于应用程序。当手机“损坏”时会发生什么,您能提供 HTTP 调试跟踪吗?
要测试 ContentType 是否确实是问题所在,请将其添加到某一页面的 Page_Load 事件中,然后在受影响的移动设备上查看该页面。
移动浏览器与桌面版本有一些怪癖,它们解析 JavaScript、处理 DOM 元素的方式不同。例如,Mobile Safari 有一个不完整的 Date.parse() 方法,这会导致 JS 在该页面上中断。
尝试在调试模式下运行移动浏览器(如果可能)并查看实际错误是什么。因为我看不出 IIS 如何随意更改内容类型,尤其是 XHTML 类型,这意味着底层 HTML 必须完美,
IIS doesn't have the funcionality you mention (to overide the content-type of output from .NET) as it's up to the application to do this. What happens on the mobiles when they 'break', can you provide a HTTP debug trace?
To test to see if the ContentType really is the problem, add this to the Page_Load event of one of your pages, then view that page on the affected mobile.
Mobile browsers have quirks to desktop versions, they parse JavaScript, handle DOM elements differently. Mobile Safari for example has an imcomplete Date.parse() method, which causes the JS to break on that page.
Try running the mobile browser in debug mode (if possible) and see what the actual error is. As I can't see how IIS would change the content type willy nilly, especially to a XHTML type which means the underlying HTML has to be perfect,
尝试将 DOCTYPE 设置为
看看是否有帮助。另外,请查看以下参考:
W3C 推荐的 Doctype 列表声明
Try setting your DOCTYPE to
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
and see if that helps. Also, have a look at the following reference:"http://www.w3.org/TR/html4/loose.dtd">
W3C Recommended list of Doctype declarations