【发布时间】:2010-12-27 08:15:27
【问题描述】:
我正在尝试创建一个 ActionResult,它的行为方式与 ViewResult 完全相同,但允许我指定 Content-Type 标头。这很困难,因为据我所知,ASP.Net MVC 交给 webforms 渲染引擎,然后使用页面上的标题设置内容类型,这种方法对我来说不可行,如果我会容易得多可以在一个中心位置改变这一点。
我尝试了以下实现,但它不起作用。 WebForms 引擎重置类型。如果之后设置也会发生同样的情况。或者,如果您尝试使用 Headers.Add 欺骗它
public class MyViewResult : ViewResult
{
public override void ExecuteResult(ControllerContext context)
{
context.HttpContext.Response.ContentType = "myContent";
base.ExecuteResult(context);
}
}
【问题讨论】:
标签: asp.net-mvc http-headers content-type