问题描述: 在ASP.NET MVC中使用Webp图像,但在Google Chrome浏览器上无法显示。
解决方法:
确保服务器端支持Webp格式:
在ASP.NET MVC中处理Webp图像:
@Url.Content
或@Url.Content("~")
生成图像URL。FileResult
返回Webp图像。示例代码如下:public ActionResult GetWebpImage()
{
var imagePath = Server.MapPath("~/Content/Images/image.webp");
return File(imagePath, "image/webp");
}
使用HTML标签picture
来处理Webp图像:
picture
标签来指定不同格式的图像文件。示例代码如下:
使用JavaScript来检查浏览器是否支持Webp图像:
请注意,要让Webp图像在Google Chrome上正常显示,必须确保服务器端和浏览器都支持Webp格式。