2

あるサーバーに画像ファイルを配置し、他のサーバーにアプリケーションを配置しました。

私が書いたコードの下で、その画像にアクセスしたい:

default.aspx には、

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

GetImage.aspx では、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();
        }
    }

しかし、私はエラーが発生しています

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

どこが間違っているか教えてください。Server.MapPath 以外に必要なものはありますか? 私のイメージは他のサーバーにあるためです。

編集

  • コンピューターに画像フォルダーがあります
  • I have created a web app in other computer [same network], deployed in IIS, image is displayed correctly. With path like http://10.67.XX.XX/websiteName/Default.aspx
  • but when I am trying to access the same from my comupter or any other computer, I am not able to see the image.
4

2 に答える 2

4

を使用しないでくださいServer.MapPath。これは、サイトの下の仮想パスをファイル システムの下の物理パスにマップするために使用されます。ファイルが別のサーバーに存在する場合は、名前を付けずに直接アクセスしてくださいServer.MapPath

于 2011-11-01T18:14:16.997 に答える