来自UNC路径的html图像源 [英] html Image source from UNC path
问题描述
我需要将图像源设置为网络上的某个位置.
I need to set an image source to a location on the network.
该图像位于machineName \ mappedPath \ abc.jpg.
The image is located at machineName\mappedPath\abc.jpg.
尽管我需要它在IE v9及更高版本中运行,但它不会在任何浏览器中加载.当我检查源代码中的位置时,它设置为
It does not load in any browser though all I need it to work in is IE v9 and above. When I inspect the location in the source it is set to
<img src="\\machineName\mappedPath\abc.jpg">
当我右键单击IE中的图像占位符并查看属性时,我看到地址设置为
When i right click on the image placeholder in IE and look at the properties I see the address is set to
file://machineName/mappedPath/abc.jpg
将文件浏览器与这些路径一起使用可以很好地打开图像.
Using file explorer with either of those paths opens the image fine.
我尝试添加IP.无法添加域名,因为它不在域中.
I've tried adding IP. Can't add a domain name as its not on a domain.
我尝试将源设置为正下方的其他路径.我读过一些地方需要5个正斜杠,但并没有任何作用
Other paths I've tried setting the source to directly below. I've read a few places that 5 front slashes are required but it hasn't made any difference
<img src="file://\\machineName\mappedPath\abc.jpg">
<img src="file:////\\machineName\mappedPath\abc.jpg">
<img src="file://///\\machineName\mappedPath\abc.jpg">
<img src="file:////machineName/mappedPath/abc.jpg">
<img src="file://///machineName/mappedPath/abc.jpg">
<img src="\\machineName\mappedPath\abc.jpg">
我还尝试通过添加防火墙规则来启用文件共享
I've also tried enabling file sharing by adding a firewall rule
顺便说一句,该路径是否必须映射为网络驱动器,或者是否足以将其设置为网络共享?
On a side note, does the path have to be mapped as a network drive or is it sufficient to set it up as a network share?
Not a definitive source but this is pretty common kind of information I've come across https://jonlabelle.com/snippets/view/html/create-html-link-to-unc-path , but for which won't work for me (in IE)
推荐答案
我发现了这篇文章.它可能具有一些相关信息.
I've found this post. It might have some relevant information.
以下是 Paul Zahra 的答案:
FireFox无法显示网络图像,因此我创建了扩展HtmlHelper的MVC帮助器.
FireFox would not display networked images so I created an MVC helper that extends HtmlHelper.
public static class ImageHelper
{
/// <summary>Converts a photo to a base64 string.</summary>
/// <param name="html">The extended HtmlHelper.</param>
/// <param name="fileNameandPath">File path and name.</param>
/// <returns>Returns a base64 string.</returns>
public static MvcHtmlString PhotoBase64ImgSrc(this HtmlHelper html, string fileNameandPath)
{
var byteArray = File.ReadAllBytes(fileNameandPath);
var base64 = Convert.ToBase64String(byteArray);
return MvcHtmlString.Create(String.Format("data:image/gif;base64,{0}", base64));
}
}
在MVC视图中使用,如下所示:
use in the MVC View like so:
using
<img src="@Html.PhotoBase64ImgSrc(image)" height="60px" width="60px" alt="photo" />
@ Html.PhotoBase64ImgSrc(image)中的图像"是纯网络UNC,例如
here the 'image' in @Html.PhotoBase64ImgSrc(image) is a pure network UNC, e.g.
//Photos/ebaebbed-92df-4867-afe8-0474ef8644eb.jpg
这篇关于来自UNC路径的html图像源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!