asp.net - Azure blob 容器中的图像未显示在 ASP.net 页面上的 ListView 中
问题描述
我正在Listview
从 sql server 数据库加载一个。行包含一个blob ID
. 我blob ID
从 blob 容器的基本 url 构造 s 然后尝试显示图像。什么都没发生。这是我的代码:
protected void PhotosListView_ItemDataBound(object sender, ListViewItemEventArgs e)
{
var itm = e.Item;
ImageButton imgBtn = (ImageButton)itm.FindControl("itemImageButton");
Label TNlbl = (Label)itm.FindControl("BlobPhotoIDLabel");
string blobContainerId = (string)Session["BlobContId"];
string imgUrl = blobClient.StorageUri.PrimaryUri + blobContainerId.ToLower() + "/" + TNlbl.Text;
imgBtn.ResolveClientUrl(imgUrl);
}
这是标记:
<td runat="server" style="background-color: #DCDCDC; color: #000000;">
<asp:ImageButton ID="itemImageButton" runat="server"
CommandArgument="<%# Container.DataItem %>"
Width="180" Height="120"
OnCommand="itemImageButton_Command"/>
<br />PhotoId:
<asp:Label ID="PhotoIdLabel" runat="server" Text='<%# Eval("PhotoId") %>' />
<br />PhotoTitle:
<asp:Label ID="PhotoTitleLabel" runat="server" Text='<%# Eval("PhotoTitle") %>' />
// etc
它的见鬼的是另一个页面上的类似代码工作正常。我错过了什么?我也在数据绑定和数据绑定事件中尝试过。数据库中的标题和其他数据显示正常。构造的 Blob url 似乎有效。
解决方案
构造的 Blob url 似乎有效。
您可以尝试将他的 blob url 放在浏览器中以检查图像是否可用。
如果您无法在浏览器中查看它,那么正如 Gaurav 所说,检查您容器的Public Access Level
. 它应该是Blob
orContainer
而不是Private(no anonymous access)
.
如果 url 有效,则使用以下代码显示图像:
Url=imgBtn.ResolveClientUrl(imgUrl); //Gets a URL that can be used by the browser.
imgBtn.imageUrl(Url);
更多详情ResolveClientUrl
,可以参考这篇文章。
推荐阅读
- java - 使用spring boot(安全)和keycloak启用角色身份验证?
- ninject - GlobalConfiguration.Configuration.UseNinjectActivator 与 Hangfire.Ninject 不存在
- mobile - 如何构建一个向后端 API 提交大量表单数据的 Flutter 应用程序
- postgresql - 这些索引是否对 customer_id 做同样的事情?
- r - eval 中的错误:找不到 dateRangeInput 的对象
- android - 使用 Glide 从 gif 中删除不必要的白色背景?
- sql-server - 在 MSSQL 中选择带有条件的上一行和下一行
- autodesk-forge - 在伪造查看器中加载多个模型(聚合)并默认将其他模型加载为隐藏,直到用户从模型浏览器中选择
- java - Web3j ECKeyPair 到 KeyPair
- python-3.x - 如何使用 python 从表中提取数据?