简体   繁体   English

图像未使用 asp.net 显示

[英]The image is not displaying using asp.net

In the below code i have a image i have pass image url from codebehind but it is not displaying the image.在下面的代码中,我有一个图像,我从代码隐藏中传递了图像 url,但它没有显示图像。 The url location is C:\\Search\\Searchdoc\\Documents\\Desert.jpeg url 位置是 C:\\Search\\Searchdoc\\Documents\\Desert.jpeg

 public string strClientName = "Searchdoc";
 public string strDocumentFolder = "Documents";
 string Imgdocname = SearchDoc.DocumentName;
 string fileExt = System.IO.Path.GetExtension(Imgdocname);
 fileExt = fileExt.ToLower();
 if (fileExt == ".jpeg" || fileExt == ".jpg")
 {
     docimg.Src = "~/" + Search+ "/"  + strClientName + "/" + strDocumentFolder + "/" + Imgdocname;
     docimg.Visible = true;
 }
 else
 {
     docimg.Src=  "~/Search/Searchdoc/Documents/image.jpeg";
     docimg.Visible = true;
 }

Well for a start, you are using the ~ character which indicates the root directory of the application.首先,您使用的是~字符,它表示应用程序的根目录。

Since you are saying that the image is in C:\\Search\\Searchdoc\\Documents\\ then that won't be found, since your code is actually looking in projectRoot\\Search\\Searchdoc\\Documents既然你说图像在C:\\Search\\Searchdoc\\Documents\\那么C:\\Search\\Searchdoc\\Documents\\不会被找到,因为你的代码实际上是在projectRoot\\Search\\Searchdoc\\Documents

As for how to get this image to show in a webpage, it won't simply work for accessing it from the C drive.至于如何让这个图像显示在网页中,它不能简单地从 C 驱动器访问它。 IIS will not serve images that aren't in the web site folder structure. IIS 不会提供不在网站文件夹结构中的图像。 I would suggest moving it into the website.我建议把它移到网站上。

If you need to keep it stored in a folder outside your website, you would need to look at streaming it, or using a sort of proxy page.如果您需要将其存储在网站外的文件夹中,则需要查看流式传输,或使用某种代理页面。 Have a look at the answer here: How to display image which is stored in local drive?看看这里的答案: 如何显示存储在本地驱动器中的图像? to get an idea of the proxy method了解代理方法

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM