如何使用Visual StudioconfigurationIIS进行SVG和Webtesting?

比方说,我有一个简单的网页与svg图像在其中:

<img src="foobar.svg" alt="not working" /> 

如果我把这个页面设置为静态html页面并直接查看svg。 如果我input这个svg的地址 – 它会显示出来。

但是,当我作为.aspx页面,并从Visual Studio中dynamic启动它,我得到alt文字。 如果我input这个svg的地址(从localhost,而不是本地文件) – 浏览器试图下载而不是显示。

我已经在IIS中定义了MIMEtypes(对于整个服务器 – “image / svg + xml”)并重新启动了IIS。 和以前一样的效果。

问题:我应该多做些什么?

更新

WireShark将无法工作(这是在文档中),我也试过RawCap,但它不能跟踪我的连接(奇数),幸运的是小提琴手工作:

来自客户:

 GET http://127.0.0.1:1731/svg/document_edit.svg HTTP/1.1 Host: 127.0.0.1:1731 User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:10.0.1) Gecko/20100101 Firefox/10.0.1 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Accept-Language: en-us,en;q=0.5 Accept-Encoding: gzip, deflate Connection: keep-alive 

从服务器回答:

 HTTP/1.1 200 OK Server: ASP.NET Development Server/10.0.0.0 Date: Thu, 16 Feb 2012 11:14:38 GMT X-AspNet-Version: 4.0.30319 Cache-Control: private Content-Type: application/octet-stream Content-Length: 87924 Connection: Close <?xml version="1.0" encoding="UTF-8" standalone="no"?> <!-- Created with Inkscape (http://www.inkscape.org/) --> <svg xmlns: *** FIDDLER: RawDisplay truncated at 128 characters. Right-click to disable truncation. *** 

为了logging,这里是对提琴手有用的问答: https : //stackoverflow.com/questions/826134/how-to-display-localhost-traffic-in-fiddler-while-debugging-an-asp-net-applicati

    从您的Fiddler跟踪看来,您正在使用内置的Visual Studio Web服务器为您的页面提供服务:

     Server: ASP.NET Development Server/10.0.0.0 

    如果这是由IIS7服务,那么我们会看到:

     Server: Microsoft-IIS/7.5 

    内置的Visual Studio Web服务器只能使用一组有限的MIMEtypes,并且不知道您为IIS7设置的MIMEtypes。 我写了一个堆栈溢出一个类似的问题的答案回来:

    使用ASP.NET开发服务器设置MIMEtypes

    内置的服务器正在为.svg文件提供服务:

     Content-Type: application/octet-stream 

    这可能是导致浏览器提示下载的原因。

    在Visual Studio中,通过打开站点的项目属性并从垂直选项卡列表中select“Web”选项卡,检查您是否使用IIS Express:

    在这里输入图像描述

    如果你没有安装IIS 7.5 Express,你可以从这里得到它:

    http://www.microsoft.com/download/en/details.aspx?id=1038

    您将需要Visual Studio 2010 Service Pack 1充分利用:

    http://support.microsoft.com/kb/983509

    IIS Express支持

    Visual Studio 2010 SP1使您能够使用Internet信息服务(IIS)7.5 Express作为网站和Web应用程序项目的本地托pipe服务器。

    注意 IIS 7.5 Express不包含在SP1中,您必须单独下载。 有关更多信息,请访问以下博客: http : //weblogs.asp.net/scottgu/archive/2011/01/03/vs-2010-sp1-beta-and-iis-developer-express.aspx

    完成之后,可以将.svg mimetypes添加到应用程序的web.config文件中:

     <configuration> <system.webServer> <staticContent> <mimeMap fileExtension=".svg" mimeType="image/svg+xml" /> </staticContent> </system.webServer> </configuration> 

    如上所述,卡西尼忽略web.config中的这些设置,所以必须使用IIS Express(VS项目设置) https://stackoverflow.com/questions/5924647/setting-mime-types-using-the-asp-networking开发服务&#x5668;

    要获得有关如何使用pipe理用户界面configurationMIMEtypes或使用IIS或IIS Express的web.config,请参阅:http: in-iis-for-a-website-or-global /和http://4rapiddev.com/tips-and-tricks/add-mime-type-flv-mp4-to-web-config-in-iis-7 /

    我已经使用Kev的答案,通过:

    1. 从Web平台安装程序安装IIS 8.0 Express
    2. 更改项目的属性以使用IIS Express并为其创build虚拟目录
    3. 在web.config的configuration中添加→system.webServer
     <staticContent> <remove fileExtension=".svg" /> <mimeMap fileExtension=".svg" mimeType="image/svg+xml" /> </staticContent> 

    我的解决方法是在本地创build我自己的httphandler,它覆盖了svg的内容types。

     public class SvgHandler : IHttpHandler { public bool IsReusable { get { return false; } } public void ProcessRequest(HttpContext context) { context.Response.ContentType = "image/svg+xml"; context.Response.BinaryWrite(File.ReadAllBytes(context.Request.PhysicalPath)); context.Response.End(); } } 

    并在web.config我补充说:

     <httpHandlers> <add verb="*" path="*.svg" type="SvgHandler" /> </httpHandlers> 

    使用这种解决scheme,您不必使用IIS Express,只需在Visual Studio 2010中使用常规开发服务器即可

    我正在运行IIS7,并能够通过右键单击IIS中的服务器并select属性来解决此问题。 然后我点击MIMEtypes…button。 然后我点击了New。 对于我在.svg中input的扩展名。 对于在image / svg + xml中键入的MIMEtypes。 我然后保存是所有,并从命令提示符做了iisreset。 工作很好。

    如果你有访问IIS,那么这也解决了这个问题: http : //httpjunkie.com/2014/884/svg-no-iis/