Webp图像未通过ASP.NET mvc显示在Google Chrome上

问题描述 投票:0回答:1

我一直在尝试在我的网站上使用Webp图像,但它们会在所有浏览器上显示为损坏的图像。

我尝试过dejanstojanovic的解决方案(我没有完全了解那里发生的事情,虽然我确实理解它是在检查浏览器是否与webp兼容然后发送webp版本,如果它是其他它发送了一个png或jpeg然而,这不起作用。同样,我尝试了deanhume的解决方案,但同样,这也没有用。两个代码都返回了一个应该由ch​​rome支持的webp文件,但是页面上有一个损坏的图像。我通过将png文件和webp文件放在同一个文件夹中并显示它们来检查以确保它不是路径的错误。 png文件工作正常,但是缺少webp文件。此外,如果我使用原始HTML,那么webp文件也可以工作,而不是使用ASP.NET。

_layout.cshtml

        <h5 class="footer-header">Contact Info</h5>
        <p class="footer-text">Contact us if you want a custom made dress, or just want to know where your package might be.</p>
        <div class="row">
            <div class="col-md-1">
                <img style="height:50px; width:50px" src="~/Images/LocationPin100h.webp" />
                <img style="height:50px; width:50px" src="~/Images/LocationPin100h.png" />
            </div>
        </div>

views文件夹中的web.config

<system.webServer>
    <handlers>
      <remove name="BlockViewHandler"/>
      <add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" />
      <remove name="WebPHandler" />
      <add name="WebPHandler" type="Web.Images.WebP.RequestHandler, Web.Images.WebP" path="*.webp" verb="GET" />
    </handlers>
    <staticContent>
      <mimeMap fileExtension=".webp" mimeType="image/webp" />
    </staticContent>
  </system.webServer>

它在页面上的显示方式:https://ibb.co/QjJkqv7

enter image description here

c# asp.net asp.net-mvc webp
1个回答
0
投票

我已经弄清楚了。有两个Web.config文件。一个位于项目根文件夹中,另一个位于views文件夹中。我不得不补充:

<system.webServer>
  <staticContent>
    <mimeMap fileExtension=".webp" mimeType="image/webp" />
  </staticContent>
</system.webServer>

进入位于根文件夹中的web.config文件,而不是像我以前那样位于views文件夹中的文件。

© www.soinside.com 2019 - 2024. All rights reserved.