0
我正在根据用户选择来设置inline
或attachment
的处置方式。它工作但非常间歇。一旦我在同一个浏览器中选择内嵌相同的文件,它就会按预期工作。一旦我切换到附件,除非关闭并重新打开浏览器,否则我无法获得所需的结果。我确实清楚了上下文并且清除了它。C#中的内容处置问题
下面是我使用的代码:
public void GetResult(ControllerContext context)
{
context.HttpContext.Response.Buffer = true;
context.HttpContext.Response.Clear();
context.HttpContext.Response.ContentType = ContentType;
ContentDisposition disposition = new ContentDisposition();
disposition.FileName = FileName;
disposition.Inline = this.ContentDispositionType == ContentDispositionType.Inline ? true : false;
context.HttpContext.Response.AddHeader("content-disposition", disposition.ToString());
context.HttpContext.Response.WriteFile(context.HttpContext.Server.MapPath(Path));
context.HttpContext.Response.Flush();
context.HttpContext.Response.End();
}
谢谢,这似乎工作,虽然我必须进一步测试。另外,为什么有些文件总是作为附件呈现,即使它们被指定为内联? – DotnetDude 2010-07-07 17:29:33
如果浏览器不知道内容类型,因此不知道运行哪个应用程序将是一个附件下载 – 2010-07-07 17:45:46