从其他服务器访问图像

编程入门 行业动态 更新时间:2024-10-26 10:34:55
本文介绍了从其他服务器访问图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

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.

更多推荐

从其他服务器访问图像

本文发布于:2023-11-16 21:53:11,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1607619.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:图像   服务器

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!