从其他服务器访问图像 [英] Accessing image from other server

查看:163
本文介绍了从其他服务器访问图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我放在一台服务器和应用程序的其他服务器上的图像文件

I have image file placed on the one server and application on other server.

我要访问该图像,下面的代码我已经写:

I want to access that image, below code I have written:

在Default.aspx的,我有

On default.aspx, I have

 <asp:Image ID="Image1" runat="server"  ImageUrl= "GetImage.aspx?imgName=MyImage.jpg" />

和上GetImage.aspx,我已经写上的Page_Load

and on GetImage.aspx, I have written the below code on page_load

 protected void Page_Load(object sender, EventArgs e)
    {
        // Changing the page's content type to indicate the page is returning an image
        Response.ContentType = "image/jpg";
        var imageName = Request.QueryString["imgName"];
        var path = "//SERVER/FOLDER/" + imageName;


        if ((string.IsNullOrEmpty(imageName) == false))
        {
            // Retrieving the image
            System.Drawing.Image fullSizeImg;
            fullSizeImg = System.Drawing.Image.FromFile(Server.MapPath(path));
            // Writing the image directly to the output stream
            fullSizeImg.Save(Response.OutputStream, ImageFormat.Jpeg);
            // Cleaning up the image
            fullSizeImg.Dispose();
        }
    }



但我得到错误的。

But I am getting error at

fullSizeImg = System.Drawing.Image.FromFile(使用Server.Mappath(路径));

fullSizeImg = System.Drawing.Image.FromFile(Server.MapPath(path));

请让我知道我是不正确。我是否需要使用Server.Mappath比别的其他?因为我的形象是其他服务器上。

Please let me know where I am incorrect. Do I need to anything else other than Server.MapPath ? because my image is on other server.

修改


  • 我有图像文件夹在我的电脑

  • 我已经建立在其他计算机[同一网络],部署
    在IIS的web应用程序,正确显示图像。有了这样
    的http://10.67.XX.XX/websiteName/Default.aspx

  • 但是当我试图从我comupter或任何其他
    计算机访问相同的,我不能够看到的图像。

推荐答案

您不应该使用使用Server.Mappath 。这是用于你的网站下的物理路径虚拟路径下的文件系统映射。如果该文件在另一台服务器上存在,只是名称直接访问它,不用使用Server.Mappath

You shouldn't use Server.MapPath. This is used to map virtual paths under your site to physical paths under file system. If the file exists on another server, just access it by name directly, without Server.MapPath.

这篇关于从其他服务器访问图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆