【问题标题】:Why the Generated ImageUrl is wrong为什么生成的 ImageUrl 是错误的
【发布时间】:2013-09-30 12:17:55
【问题描述】:

我在我的项目中的一个文件夹中存储了图像,名称如下

(ProductID).Extention

图像的其他细节都存储在数据库中

我已使用以下过程来获取图像

create proc prcMainPhoto(@ProductID int)
as 
select p.ProductID ,
isnull(( select top 1 convert(varchar,PhotoID,10) + '.' + ExtName from ProductPhoto where ProductID= p.ProductID ),'NoImage.jpg')as MainPhoto
from ProductInfo as p where p.ProductID=@ProductID

并将 imageurl 提供给这样的图像

DataSet ds1 = new ClientProductView().GetMainPhotoInDeatailPage(productid);
string img = ds1.Tables[0].Rows[0]["MainPhoto"].ToString();
imgmain.ImageUrl ="./productimages / main / "+ img;

但是图片正在生成这个网址

http://localhost:1030/SShopping%20Website/ProductDetails.aspx?ProductID=1#

我已在页面 ProductDetails 中编码,该页面位于外部

请帮忙

【问题讨论】:

    标签: asp.net sql-server-2008 c#-4.0 imageurl


    【解决方案1】:

    必须像这样给imageurl

     DataSet ds1 = new ClientProductView().GetMainPhotoInDeatailPage(1);
            string img = ds1.Tables[0].Rows[0]["MainPhoto"].ToString();
            image.ImageUrl = string.Format("productimages/main/" + img);
    

    【讨论】:

    • 这是否意味着图像路径之前的 ./ 是问题所在。
    【解决方案2】:

    我认为这里的问题是ImageUrl can only be assigned with either a relative or an absolute URL。我认为使用 .在您的 URL 路径中是导致问题的原因。

    【讨论】:

      【解决方案3】:

      尝试使用相对路径设置图片 url:

      imgmain.ImageUrl ="~/productimages/main/" + img;
      

      【讨论】:

      • 你如何定义imgmain?你能发布更多的代码吗
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-01-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-21
      • 2014-05-07
      • 1970-01-01
      相关资源
      最近更新 更多