无法从ASP.NET中的C:\读取图像 [英] Can't read images from C:\ in ASP.NET

查看:114
本文介绍了无法从ASP.NET中的C:\读取图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我意识到这是一个边缘情况,但似乎asp.net不允许从根驱动器读取图像。为了测试这个,我编写了以下非常简单的应用程序:

I realize this is an edge case, but it seems that asp.net doesn't allow reading images from the root drive. To test this I wrote the following very simple application:

在页面上我有:

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

在后面的代码中我有:

test.ImageUrl = @"C:\test\image.jpg";
test.AlternateText = File.ReadAllText(@"C:\test\text.txt");

两个文件都按照您的预期存在并具有正确的权限。查看页面源代码时,我们会看到如下所示的img标记:

Both files exist as you'd expect and have the correct permissions. When viewing the source of the page we get an img tag that looks like the following:

<img id="test" src="C:\test\image.jpg" alt="some text to read" style="border-width:0px;" /> 

当我在VS中运行时,不显示任何图像。如果我复制源,将其粘贴到html文件中并将其加载到浏览器中,显示图像。任何人都可以解释为什么会这样吗?

When I run this in VS no image is displayed. If I copy the source, paste it into an html file and load it into a browser the image is displayed. Can anybody explain why this is?

推荐答案

浏览器阻止显示图像。我创建了一个静态HTML页面,其中包含一个标签,其src指向我本地文件系统上的图像。如果我在本地打开HTML页面,一切都按预期工作。但是,当我在Web服务器中托管静态HTML页面时,它停止工作。

The browser is preventing the images from being displayed. I created a static HTML page containing an tag whose "src" pointed to an image on my local file system. If I open the HTML page locally, everything works as expected. However, when I hosted the static HTML page in a web server, it stopped working.

我从远程服务器和本地文件加载HTML页面时运行了ProcMon被访问(一些列被截断用于显示目的):

I ran ProcMon while loading the HTML page from the remote server, and the local file was accessed (some columns truncated for display purposes):


iexplore.exe    6376    QueryDirectory  C:\test.jpg SUCCESS test.jpg
iexplore.exe    6376    QueryOpen   C:\test.jpg SUCCESS 
iexplore.exe    6376    QueryDirectory  C:\test.jpg SUCCESS 
iexplore.exe    6376    CreateFile  C:\test.jpg SUCCESS
iexplore.exe    6376    ReadFile    C:\test.jpg SUCCESS
iexplore.exe    6376    CloseFile   C:\test.jpg SUCCESS

然而,IE没有显示图像。我用Firefox重复测试。在本地访问时,ProcMon结果是相同的。远程访问时,ProcMon不会产生任何输出。

However, IE did not display the image. I repeated the test with Firefox. When accessing locally, the ProcMon results were the same. When accessing remotely, ProcMon didn't produce any output.

这篇关于无法从ASP.NET中的C:\读取图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆