简体   繁体   English

IIS 服务器阻止访问 .webp 文件

[英]IIS server blocking access to .webp files

So I'm trying to add .webp image support for a WordPress site, which is run on IIS.因此,我正在尝试为在 IIS 上运行的 WordPress 站点添加 .webp 图像支持。

Now the image exists on the server and the file name is correct but when I try to load the image via URL address in the browser I get the 404 error.现在图像存在于服务器上并且文件名正确,但是当我尝试通过浏览器中的 URL 地址加载图像时,出现 404 错误。

404 - File or directory not found. 404 - 未找到文件或目录。 The resource you are looking for might have been removed, had its name changed, or is temporarily unavailable.您要查找的资源可能已被删除、更名或暂时不可用。

Anyone know how I might resolve this issue?有谁知道我如何解决这个问题?

I tried added <add extension=".webp" policy="CacheUntilChange" kernelCachePolicy="DontCache" /> but this doesn't work as it's to do with caching.我尝试添加<add extension=".webp" policy="CacheUntilChange" kernelCachePolicy="DontCache" />但这不起作用,因为它与缓存有关。

Is there somewhere were I can allow access to certain file types?有什么地方可以允许访问某些文件类型吗?

Do I maybe need to allow the filetype through the firewall?我可能需要允许文件类型通过防火墙吗?

I'm still new to working with IIS so I'm a little lost.我对使用 IIS 还是个新手,所以我有点迷茫。

Cheers干杯

You'll need to add this config to your webconfig file:您需要将此配置添加到您的 webconfig 文件中:

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

The fastest solution with less headache is to just add the file extension .webp to the mime types as below:减少头痛的最快解决方案是将文件扩展名.webp添加到mime types ,如下所示:

  1. Select website from IIS Manager:从 IIS 管理器中选择网站: 1. 从 IIS 管理器中选择网站

  2. Add file extension to Mime Types:将文件扩展名添加到 Mime 类型: 2. 为 Mime Types 添加文件扩展名

Ok figured it out.好吧想通了。

I had to allow the mime type in iis manager.我不得不在 iis 管理器中允许 mime 类型。

https://technet.microsoft.com/en-us/library/cc725608(v=ws.10).aspx https://technet.microsoft.com/en-us/library/cc725608(v=ws.10).aspx

Webp images are not showing, when you run or debug the application.当您运行或调试应用程序时,不会显示 Webp 图像。 Especially in IIS Express and IIS.特别是在 IIS Express 和 IIS 中。 For IIS we can go the Mime type in the app config as mentioned.对于 IIS,我们可以在应用程序配置中使用 Mime 类型,如上所述。 But for the IIS express, even though you add in app.config, it does not show up.但是对于IIS express,即使你在app.config 中添加,它也不会显示。 Just follow this procedure to resolve this issue.只需按照此过程来解决此问题。

  1. Open the IIS Express Dialog using the icon from System tray.使用系统托盘中的图标打开 IIS Express 对话框。 Check image.检查图像。 Open IIS Express from system tray从系统托盘打开 IIS Express

  2. In the dialog box, select the website.在对话框中,选择网站。 You can see the related details in the below section.您可以在以下部分查看相关详细信息。 IIS Express dialog box IIS Express 对话框

  3. See the config path, it varies for every app or site you develop.查看配置路径,它因您开发的每个应用程序或站点而异。 Click that link and you can get the config file opened in your VS studio.单击该链接,您可以在 VS Studio 中打开配置文件。 Now add the webp mime extension code along with other image types.现在添加 webp mime 扩展代码以及其他图像类型。 save the file and close it.保存文件并关闭它。

Now, you are able to view the webp images in local browsing in debug mode.现在,您可以在调试模式下在本地浏览中查看 webp 图像。 Problem resolved.问题解决了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM