开发者

Override mime type with VS Web Dev Server

I would like to serve xbaps from the VS web dev server (cassini) to Firefox, but when served from the dev server, Firefox offers to download this file. As far as I can tell, this is because the 开发者_StackOverflowdev server is serving the xbap file with a mime type of "application/octet-stream" instead of "application/x-ms-xbap", which works when served from IIS.

Does anyone know how to change the mime type which the dev server uses for *.xbap files?


you can't. WevDev.WebHost is fairly clumsy when issuing content-types and has a very limited range of specific content-types.

You can use CassiniDev. The latest release provides extended content-type support, including .xbap.

see http://cassinidev.codeplex.com/SourceControl/changeset/view/49870#894160 for a complete list of supported types.

Update: your problem may be that you installed FF after 3.5sp1 and do not have the NPWPF.dll in your FF plugins directory. Do you have this file?

Update 2 I have just released a version of CassiniDev that is a great drop in replacement for Visual Studio's Development server. It's enhancements include improved content-type support and integrated traffic logging/viewing.

http://skysanders.net/subtext/archive/2010/05/22/release-cassinidev-for-visual-studio-2008-a-drop-in.aspx


It probably too late now, but for others who get that problem here is how to solve it:

I solved it for mp4 videos but it is the same principal for any mime, just revise to your needs.

I assume you use vs2012, create IHttpHandler and copy this code into it:

public class Mp4Handler : IHttpHandler
{
    public void ProcessRequest(HttpContext context)
    {
        context.Response.ContentType = "video/mp4";
        context.Response.BinaryWrite(File.ReadAllBytes(context.request.PhysicalPath));
        context.Response.End();
    }

public bool IsReusable{ get{ return false;}}
}

And remember to add to your web.config file under system.web:

<httpHandlers>
    <add verb="*" path="*.mp4" type="[your-namespace].Mp4Handler" />
</httpHandlers>

By doing so you will not need CassiniDev to serve mp4 correctly anymore, however, CassiniDev is not evil and worth keeping - without it I wouldn't be able to verify what the problem was in the 1st place.


Note that with VS 2010 SP1, you can now use IIS Express instead of Cassini for your web projects, which gives you full control of your MIME types.

More information: http://blogs.msdn.com/b/webdevtools/archive/2011/03/14/enabling-iis-express-support-in-vs-2010-sp1.aspx

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜