简体   繁体   English

IIS 无法从 UNC 路径或虚拟目录加载图像

[英]IIS can't load image from UNC path nor Virtual directory

I just mounted a web site locally with IIS manager.我刚刚使用 IIS 管理器在本地安装了一个网站。 I can access the site from the path http://192.168.154.2/Default.aspx and I have a folder named Affiche which contains some images and is situated in a remote server from the same network.我可以从路径http://192.168.154.2/Default.aspx访问该站点,并且我有一个名为 Affiche 的文件夹,其中包含一些图像并且位于来自同一网络的远程服务器中。

To access an image I am using an aspx page GetImage.aspx which work like this:要访问图像,我使用了一个 aspx 页面 GetImage.aspx,其工作方式如下:

 var path = "//192.168.84.52/Distri/Affiche/10038P.jpg"

    if ((string.IsNullOrEmpty(imageName) == false))
    {

        try
        {
            // Retrieving the image
            System.Drawing.Image fullSizeImg;
            fullSizeImg = System.Drawing.Image.FromFile(path);
            // Writing the image directly to the output stream
            fullSizeImg.Save(Response.OutputStream, ImageFormat.Jpeg);
            // Cleaning up the image
            fullSizeImg.Dispose();
        }

        catch (System.IO.FileNotFoundException)
        {
            //MessageBox.Show("There was an error opening the bitmap." +
            //    "Please check the path.");
        }
    }

This solution works fine in localhost ( with Visual Studio), I an perfectly get the image with a link like this http://localhost:3606/GetImage.aspx , however http://192.168.154.2/GetImage.aspx does not work.此解决方案在 localhost(使用 Visual Studio)中运行良好,我完全可以通过这样的链接获取图像http://localhost:3606/GetImage.aspx ,但是http://192.168.154.2/GetImage.aspx不起作用. It will only show a broken image icon.它只会显示损坏的图像图标。

The remote can be accessed from my computer ( which already input the login) where I have installed the web server.可以从我安装了 Web 服务器的计算机(已经输入登录名)访问远程。

I tried another solution by using this solution : a virtual directory我使用此解决方案尝试了另一种解决方案: 虚拟目录

From the IIS manager I can perfectly view the files from the remote server, but when I try to access the virtual folder like this: http://192.168.154.2/afficheImage/20772G.jpg从 IIS 管理器我可以完美地查看来自远程服务器的文件,但是当我尝试像这样访问虚拟文件夹时: http://192.168.154.2/afficheImage/20772G.jpg : http://192.168.154.2/afficheImage/20772G.jpg

I have an 500.19 error with insufficient permissions.我有一个权限不足的 500.19 错误。

Is there a way to solve this please?请问有办法解决这个问题吗?

The first line of your code:代码的第一行:

var path = "//192.168.84.52/Distri/Affiche/10038P.jpg"

This is pointing to a different IP address than your website having virtual directory.这指向与您的网站具有虚拟目录不同的 IP 地址。 "192.168.154.2". “192.168.154.2”。 Are you accessing images from another server?您是否正在从另一台服务器访问图像? In that case you need to check permissions on another server as well.在这种情况下,您还需要检查另一台服务器上的权限。

Use the below line of code for path使用以下代码行作为路径

var path = @"\\\\192.168.84.52\\Distri\\Affiche\\10038P.jpg" var path = @"\\\\192.168.84.52\\Distri\\Affiche\\10038P.jpg"

This is correct notation but you gave invalid slashes.这是正确的符号,但您给出了无效的斜线。

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

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