使用 ASP.NET 开发服务器设置 MIME 类型 [英] Setting MIME types using the ASP.NET Development Server

查看:38
本文介绍了使用 ASP.NET 开发服务器设置 MIME 类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 web.config 文件中添加了以下内容,但这似乎被 Visual Studio 2010 中内置的开发服务器忽略了.有谁知道如何更改开发服务器中的 MIME 类型?

I added the following to the web.config file, but this seems to be ignored by the development server thats built into Visual Studio 2010. Does anyone know how to alter the MIME types in the development server?

<system.webServer>
    <validation validateIntegratedModeConfiguration="false"/>
    <modules runAllManagedModulesForAllRequests="true"/>
    <staticContent>
        <mimeMap fileExtension=".mp4" mimeType="video/mp4" />          
        <mimeMap fileExtension=".ogg" mimeType="audio/ogg" />          
        <mimeMap fileExtension=".oga" mimeType="audio/ogg" />          
        <mimeMap fileExtension=".ogv" mimeType="video/ogg" />          
        <mimeMap fileExtension=".webm" mimeType="video/webm" />     
    </staticContent>  
</system.webServer>

推荐答案

Visual Studio (Cassini) 内置的开发web server 没有知识,只有IIS7.x 或 IIS7.5 Express 将使用这些设置.

The built-in development web server in Visual Studio (Cassini) has no knowledge of <system.webServer>, only IIS7.x or IIS7.5 Express will consume these settings.

Visual Studio 的开发 Web 服务器中的静态文件内容类型也是硬编码的.

Also the static file content types in Visual Studio's development web server are hard coded.

来自 Microsoft.VisualStudio.WebHost.Connection(使用 .NET Reflector 反汇编):

From Microsoft.VisualStudio.WebHost.Connection (disassembled using .NET Reflector):

private static string MakeContentTypeHeader(string fileName)
{
    string str = null;
    FileInfo info = new FileInfo(fileName);
    switch (info.Extension.ToLowerInvariant())
    {
        case ".bmp":
            str = "image/bmp";
            break;

        case ".css":
            str = "text/css";
            break;

        case ".gif":
            str = "image/gif";
            break;

        case ".ico":
            str = "image/x-icon";
            break;

        case ".htm":
        case ".html":
            str = "text/html";
            break;

        case ".jpe":
        case ".jpeg":
        case ".jpg":
            str = "image/jpeg";
            break;

        case ".js":
            str = "application/x-javascript";
            break;
    }
    if (str == null)
    {
        return null;
    }
    return ("Content-Type: " + str + "
");
}

说实话,随着 IIS7.5 Express 的出现,我不明白您为什么要使用内置的 Web 服务器.在生产服务器上的部署时间方面,Cassini 可能会造成如此多的混乱,因为它与真正的交易(安全性、配置等)完全不同,而如果您可以让您的站点在 IIS7.5 Express 上运行,那么就会有相当高的部署到生产 IIS7.5 服务器上正常工作"的可能性.

To be honest, with the advent of IIS7.5 Express I can't see why you'd want to use the built-in web server. Cassini can be the cause of so much confusion when it comes to deployment time on a production server because it's nothing like the real deal (security, configuration etc) whereas if you can get your site running on IIS7.5 Express then there's a fairly high probability that deployment onto a production IIS7.5 server will "just work".

考虑到使用 IIS7.5 Express 运行非常容易,如果微软将 Cassini 服务器从下一版本的 Visual Studio 中移除,我不会感到惊讶.

I wouldn't be surprised if Microsoft yanked the Cassini server from the next version of Visual Studio given how easy it is to run with IIS7.5 Express.

这篇关于使用 ASP.NET 开发服务器设置 MIME 类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆