【问题标题】:Mime types for XSP Mono WebserverXSP Mono Webserver 的 Mime 类型
【发布时间】:2014-07-10 05:18:45
【问题描述】:

有谁知道是否可以向 XSP 网络服务器添加 mime 类型?

我正在开发一个使用 XSP 作为轻量级服务器的本地 Asp.net MVC 应用程序 (Windows)。

问题在于 XSP 没有为某些文件提供正确的 mime 类型。 一个例子是 mp4,它获取 mime 类型“application/octet-stream”而不是“video/mp4”。

这会导致 IE9/IE10 提供有关这些文件的下载对话框,而不是原生播放视频。

我尝试在 web.config 中配置 mime 类型(适用于 iis express 等其他服务器)

<mimeMap fileExtension=".mp4" mimeType="video/mp4" />

但没有成功。

此常见问题页面 http://www.mono-project.com/FAQ:_ASP.NET 听起来不太乐观:

...而且它还缺少诸如 mime 类型配置之类的功能以及人们期望从 Web 服务器获得的任何其他功能。

但也许有未记录的方式来支持不同的 mime 类型...

【问题讨论】:

    标签: asp.net-mvc video mono mime-types xsp


    【解决方案1】:

    在 Mono 开发人员的一些支持下,我找到了一个并非特定于 Mono 的解决方案。

    定义一个 HttpHandler:

    web.config

    <httpHandlers>
          <add verb="*" path="*.mp4" type="MyApp.Helpers.MimeTypeHandler" />
    </httpHandlers>
    

    MimeTypeHandler.ashx.cs

    namespace MyApp.Helpers
    {
        public class MimeTypeHandler : IHttpHandler
        {
            public bool IsReusable
            {
                get
                {
                    return false;
                }
            }
    
            public void ProcessRequest(HttpContext context)
            {
                context.Response.ClearContent();
                context.Response.ClearHeaders();
                string absolutePath = context.Server.MapPath("~" +context.Request.Url.PathAndQuery);
                var length = new System.IO.FileInfo(absolutePath).Length;
                context.Response.CacheControl = "Public";
                context.Response.AddHeader("Content-Length", length.ToString());
                context.Response.ContentType = "video/mp4";
                context.Response.WriteFile(absolutePath);
                context.Response.Flush();
                context.Response.Close();
            }
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2011-01-25
      • 2013-08-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-14
      • 2011-01-13
      • 2011-10-16
      • 2010-10-28
      相关资源
      最近更新 更多