Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
848 views
in Technique[技术] by (71.8m points)

visual studio 2010 - Setting MIME types using the ASP.NET Development Server

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>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.

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

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 + "
");
}

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".

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...