首页 文章

asp.net mvc使用.wml保持覆盖text / html内容类型

提问于
浏览
2

我只是使用纯HTML 4.01,没什么特别的 . 除诺基亚Series 40第1-5版外,我们测试过的所有移动浏览器都能正常显示这些页面 . 仔细观察,似乎IIS会自动呈现内容类型为 text/vnd.wap.wml 而不是 text/html 的html . 由于我们没有使用WAP,因此页面失败并显示错误 .

我'm using ASP.Net MVC 1.0 so I' ve添加了一个 ActionFilterAttribute 来覆盖内容类型 . 此代码运行但仍在客户端以vnd.wap.wml的形式出现 .
我正在使用这个doctype;

<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

值得注意的是vnd.wap.wml是移动浏览器指定的第一个 Accept-Encoding ,因此我假设IIS7正在为此提供服务 . 我想因为MVC并没有特别提到.html(或.aspx)文件,可能会跳过mime类型?我怀疑这可能是一个IIS修复而不是代码修复 .

任何帮助深表感谢!

1 回答

  • 5

    事实证明我没有正确实现ActionFilter ..除了OnActionExecuted方法之外,我还需要覆盖OnResultExecuted方法 . 完整属性如下所示(只需在需要时将[HtmlOverrideFilter]添加到控制器中) . 希望这有助于某人 .

    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";
        }
    }
    

相关问题