首页 > 解决方案 > Linking Image control and FileUpload control

问题描述

As the heading suggests, I'm trying to give the user the option to choose an image using the FileUpload control and after hitting the update button, display it in the Image control, existing inside a Panel control.

So far I've gotten here. This is my form.

Code 1

And this is my code.

Code 2

I let the highlighted code stay inside PageLoad function just for testing. I know it should be inside the Button's event handler.

Also, can someone explain me why the above fails to display the image even after hardcoding an absolute URL for Image.ImageUrl property. It worked when I referenced it just by giving the file name cake.png and putting the file inside the website folder. But I want to reference absolute URLs.

Any and all help is appreciated. Thanks.

标签: c#

解决方案


您正在创建一个 Web 应用程序,该应用程序可以在 Internet 上使用,并且可以在全球范围内访问。在您的示例中,该示例不起作用,您正在 Web 应用程序中从您自己的计算机上引用本地文件系统中的图像文件。您的 Web 应用程序在其自己的进程和自己的帐户/用户(IIS 的情况下为 IUSR)下运行,并且您的本地系统在不同的进程下运行。所以两个人不能这样说话。


推荐阅读