- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
由于某种原因,Firefox 无法正确处理通过我的 .NET HTTP 处理程序发送的内容;它似乎不遵守内容类型 header 。相反,它将内容视为 HTML。映射到请求的 URL 甚至具有 .csv 扩展名。 Internet Explorer 和 Chrome 正在做正确的事。 “text/css”和“application/pdf”处理程序都会出现问题。
这是我的 HTTP 处理程序的 ProcessRequest 方法的片段:
public void ProcessRequest(HttpContext context)
{
// ...
// Set the output headers
context.Response.ClearHeaders();
context.Response.ContentType = "text/csv";
context.Response.AddHeader(
"Content-Disposition", "attachment; filename=foo.csv");
// Code that writes to the output stream
// ...
context.Response.End();
}
我的响应中缺少什么能让 Firefox 按预期识别内容类型?
编辑 1:
当使用 Firefox Live HTTP Headers 扩展时,我看到,我得到了以下 header 。看起来我的 ContentType header 丢失了。
HTTP/1.x 200 OK
Server: ASP.NET Development Server/9.0.0.0
Date: Thu, 31 Dec 2009 02:34:09 GMT
X-AspNet-Version: 2.0.50727
Content-Disposition: attachment;filename="foo.csv"
Cache-Control: private
Content-Type: text/html
Content-Length: 66682
Connection: Close
编辑 2:
发现问题。在我的处理程序中,我使用 context.Server.Execute
从 ASPX 模板生成 HTML,然后处理该 HTML。换句话说,我没有使用 context。 Server.Execute
直接输出到响应。尽管如此,运行该方法会修改当前上下文的响应 header 。所以这是在撤消我设置的标题。将修改 header 的代码移动到 context.Server.Execute
之后解决了这个问题。
这只影响 Firefox 的原因是因为其他浏览器使用文件扩展名而不是内容类型。 Firefox 做正确的事。
最佳答案
这看起来确实很奇怪。我会安装 Live HTTP Headers Firefox 的附加组件只是为了确认 Firefox 确实如您所料看到了这两个 header 。
RFC 2616 似乎也建议 placing quotes round the filename ,所以您也可以尝试一下。
关于.net - 使用 IHttpHandler 时,Firefox 无法正确处理内容类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1982909/
我想从 IHttpHandler 类流式传输数据。我正在从数据库中加载大量行,对它们进行序列化和压缩,然后通过网络将它们发送出去。另一方面,我希望我的客户端能够在服务器完成所有对象的序列化之前解压缩和
我有一个 global.asax,如果注册了具有特定名称的 IHttpHandler,我想检查 Application_Start 方法。我该怎么做? 处理程序可以在应用程序自己的 web.confi
我编写了一个 Ihttphandler 来下载文件: public class DescargaFichero : IHttpHandler { public void ProcessRequ
我正在尝试为 MVC Controller 执行自定义 ActionResult。在我正在查看的示例中,它显示了下面的代码片段。我的 System.Web.Mvc.MvcHttpHandle 没有实现
所以我有 UI 可以在我的应用程序中创建日历事件。创建新事件时,我会为我的所有用户(大约 3,000)创建通知。我知道这需要一段时间,因为我需要为每个用户写入数据库以创建他们的通知,所以我创建了一个继
我有一个 IHttpHandler,我相信它可以从重用中获益,因为它的设置成本很高,而且是线程安全的。但是正在为每个请求创建一个新的处理程序。我的处理程序没有被重复使用。 以下是我的简单测试用例,没有
我的问题很简单(尽管答案很可能不是):我试图决定如何在 C#/ASP.NET 中实现服务器端上传处理程序。 我已经使用了 HttpModules(IHttpModule 接口(interface))和
我正在编写一个 IHttpHandler,我需要实现一个 IsReusable 属性。当我查看 MSDN documentation它说: Gets a value indicating whethe
我想使用 IHttpHandler 方法在 .Net-Project 中使用 XSP 或更好的 mod_mono。 我有以下类(class)(很简单: public class Class1 : IH
我正在尝试让自定义处理程序适用于 ASP.NET 3.5 中的特定 URL(或一组 URL)。 处理程序实际上并没有做任何重要的事情 - 它只是记录请求。如果有人认为相关,我可以发布代码,但我真的认为
我想使用类似 HttpServerUtility.Execute 的东西执行 IHttpHandler并将处理程序响应写入 MemoryStream然后可以将其解析为 http 响应(在功能上,我想访
我有一个执行三个方法的 IHttpHandler: a = 方法_A b = 方法_B c = Method_C(a,b) 方法A和方法B的计算是完全独立的。方法 C 使用方法 A 和 B 的结果。目
我有一个实现 IRequiresSessionState 的 IHttpHandler。大多数服务器上一切正常,但有 2 台服务器(一台 IIS 7.0 和一台 IIS 7.5)给我空 session
我有一个 IHttpHandler,我想连接到 OutputCache 支持,这样我就可以将缓存数据卸载到 IIS 内核。我知道 MVC 必须以某种方式执行此操作,我在 OutputCacheAttr
出于 CORS 和安全目的,我们有一个网络应用程序通过 .NET IHttpHandler(称为 proxy.ashx)路由许多请求。一些资源加载速度快,而另一些资源加载速度慢,这取决于这些资源所需的
我已经想出了如何绕过 ServiceStack 来实现我自己的 HTTP 处理程序来提供文件作为下载,并且它运行良好。但是,我想知道现在我在 servicestack 之外,是否可以以某种方式访问
我有一个工厂,其中包含下面给出的函数: TestOperation: function(filename) { var senddata = { filename: filen
我制作了一个派生自 MvcHandler 的自定义处理程序。我的路由使用自定义 RouteHandler,它返回 GetHttpHandler() 的新处理程序,并且我在自定义处理程序中重写 Proc
我有处理文件上传的 ASP.NET IHttpHandler 模块。我在配置文件中将文件大小限制设置为 50mb 但上传 1
在我的 IHttpHandler 类(对于 .ashx 页面)中,我想在目录中搜索某些文件,并返回相关 URL。我可以获取文件,没问题: string dirPath = context.Server
我是一名优秀的程序员,十分优秀!