asp.net mvc的保持压倒一切的text / html内容类型与的.wml [英] asp.net mvc keeps overriding text/html content-type with .wml

查看:178
本文介绍了asp.net mvc的保持压倒一切的text / html内容类型与的.wml的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发一个网站,该网站将在移动(手机)设备上查看。我只是用普通的HTML 4.01,没什么特别的。该页面呈现在所有我们测试过,除了诺基亚40系列1-5th版本的移动浏览器的罚款。在仔细检查,似乎IIS被自动呈现与内容类型文/ vnd.wap.wml 的HTML而不是的text / html 。因为我们没有使用WAP,网页因错误而失败。

I'm developing an website which is to be viewed on mobile (cellphone) devices. I'm just using plain HTML 4.01, nothing special at all. The pages render fine on all the mobile browsers we've tested, except for Nokia Series 40 1-5th editions. On closer inspection, it seems that IIS is automatically rendering the html with the content-type of text/vnd.wap.wml instead of text/html. Since we're not using WAP, the page fails with an error.

我使用ASP.Net MVC 1.0,所以我已经添加了一个 ActionFilterAttribute 来覆盖内容类型。这code同时运行,但仍然出来作为客户端vnd.wap.wml。

 我使用这个DOCTYPE;

I'm using ASP.Net MVC 1.0 so I've added a ActionFilterAttribute to override the content-type. This code runs but still comes out as vnd.wap.wml on the client side.
I'm using this doctype;

<?XML版本=1.0编码=UTF-8&GT?;
!< D​​OCTYPE HTML PUBLIC - // W3C // DTD HTML 4.01过渡// ENhttp://www.w3.org/TR/html4/loose.dtd>

值得注意的是,vnd.wap.wml是第一个的Accept-Encoding 通过手机浏览器指定的,所以我想IIS7正在服刑它为这个原因。我猜是MVC没有具体提到为.html(或的.aspx)文件,可能的MIME类型被跳过?我怀疑这可能是一个IIS的修复,而不是一个code-修复。

It's worth noting that the vnd.wap.wml is the first Accept-Encoding specified by the mobile browser, so I assume IIS7 is serving it up for that reason. And I guess as MVC doesn't specifically refer to .html (or .aspx) files, maybe the mime-type is being skipped? I suspect this is probably an IIS fix rather than a code-fix.

任何帮助很多AP preciated!

Any help is much appreciated!

推荐答案

原来我没有正确实施ActionFilter ..我需要重写除了OnActionExecuted方法OnResultExecuted方法。完整的属性看起来是这样的(刚加入[HtmlOverrideFilter]你的控制器需要的地方)。希望这可以帮助别人。

Turns out I hadn't implemented the ActionFilter correctly.. I needed to override the OnResultExecuted method in addition to the OnActionExecuted method. The full attribute looks like this (just add [HtmlOverrideFilter] to your Controllers where needed). Hope this helps someone.

internal class HtmlOverrideFilter : ActionFilterAttribute
{
    public override void OnActionExecuted(ActionExecutedContext filterContext)
    {
        filterContext.HttpContext.Response.ContentType = "text/html";
    } 

    public override void OnResultExecuted(ResultExecutedContext filterContext)
    {
        filterContext.HttpContext.Response.ContentType = "text/html";
    }
}

这篇关于asp.net mvc的保持压倒一切的text / html内容类型与的.wml的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆