简体   繁体   中英

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

I just mounted a web site locally with IIS manager. 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.

To access an image I am using an aspx page GetImage.aspx which work like this:

 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. 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.

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

I have an 500.19 error with insufficient permissions.

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. "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"

This is correct notation but you gave invalid slashes.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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