如何在aspx文件中显示图像?

时间:2015-04-02 09:32:25

标签: c# asp.net image

我正在使用此

<asp:Image ID="UserPicture" runat="server" />

在aspx文件中显示图像,后面的代码如下所示:

string imagePath = "~/ProfilePictures/" + UsernameBox.Text; UserPicture.ImageUrl = imagePath;

但是在加载页面后,图片不会显示,只显示默认图片图标。有什么建议如何正确吗? (也许调整图像大小?)

由于

1 个答案:

答案 0 :(得分:0)

User Server.MapPath()方法:

string imagePath = "ProfilePictures/" + UsernameBox.Text;

确保UsernameBox.Text必须是xyz.jpg或任何带扩展名的文件名。