简体   繁体   English

在GridView中从DB显示图像,其中PAth在其他驱动器中

[英]Display Image in GridView from DB where PAth is in other Drive

I want to display images in grid view depending on the users ID. 我想根据用户ID在网格视图中显示图像。 The Problem is that my images are stored in another drive and not in the website folder. 问题是我的图像存储在另一个驱动器中,而不是网站文件夹中。 Which does not allow me to show the images even though I get the path. 即使获得路径,这也不允许我显示图像。

According to this link How to display image which is stored in local drive? 根据此链接如何显示存储在本地驱动器中的图像?

In that post the answer suggests creating another page which passes a query string or something according to the ID. 在该帖子中,答案建议创建另一个页面,该页面根据ID传递查询字符串或其他内容。

I am new at this and don't know how to work with query string. 我是新来的,不知道如何使用查询字符串。

I have written the following code:- 我写了以下代码:

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false">
         <Columns>
             <asp:BoundField DataField="User_ID" HeaderText="User_ID" />
             <asp:ImageField DataImageUrlField="Photo_File_Path" HeaderText="Photo_File_Path">
             </asp:ImageField>
         </Columns>
     </asp:GridView>


SqlConnection con = new SqlConnection(CS);
        SqlCommand cmd = new SqlCommand("SELECT User_ID, Photo_File_Path FROM User_M", con);
        con.Open();

        SqlDataReader rdr = cmd.ExecuteReader();
        GridView1.DataSource = rdr;
        GridView1.DataBind();
        con.Close();

How do I get my code to work with the query string OR if there is any other way I can display the images. 如何使我的代码与查询字符串配合使用,或者还有其他显示图像的方法。

Thank you. 谢谢。

I don't know if this still applies, but here goes: 我不知道这是否仍然适用,但是这里是:

Your WebServer is running under a user account, as are all services on your computer. WebServer和计算机上的所有服务都以用户帐户运行。 It is usually an accountname like IUSR or something like it. 通常是一个帐户名称,例如IUSR或类似名称。

On the drive where you have the files, you can right-click on the folder and allow read-access to this user by going to access permissions. 在拥有文件的驱动器上,可以右键单击该文件夹,并通过访问权限允许对该用户进行读访问。

This ONLY applies to servers that you can control yourself, of course, and will not scale out to Azure or other hosted environments. 当然,这仅适用于您可以控制自己的服务器,并且不会扩展到Azure或其他托管环境。 But it should solve your problem, provided that it is still how one deals with this exact problem. 但这仍然可以解决您的问题,只要仍然可以解决这个确切的问题。

EDIT: The post that you linked to is 5 years old. 编辑:您链接到的帖子是5岁。 I'd be wary of trusting it fully :) 我会完全信任它:)

While not really an answer to your specific question, you might want to look at setting up a virtual directory in your IIS, to allow you to map a directory from anywhere on your machine to for example a subdirectory of your site. 虽然这并不是对您的特定问题的真正答案,但您可能希望查看在IIS中设置虚拟目录的情况,以允许您将目录从计算机上的任何位置映射到站点的子目录。

So say you have your site in C:\\sites\\mySite you can map the directory D:\\data\\images\\ to appear to be available at C:\\sites\\mySite\\userImages , so your site can reference it by http:\\\\mysite.com\\userImages . 因此,假设您的网站位于C:\\sites\\mySite ,则可以将目录D:\\data\\images\\映射为在C:\\sites\\mySite\\userImages ,因此您的网站可以通过http:\\\\mysite.com\\userImages引用http:\\\\mysite.com\\userImages

This might be an easier way of organizing the site structure, and you can move that physical directory without the website code having to change. 这可能是组织站点结构的一种更简便的方法,您可以移动该物理目录而无需更改网站代码。

Hope you get it working, any way you proceed. 希望您能以任何方式使它正常工作。 :) :)

EDIT: This link provides the information that you need to set this up: https://www.iis.net/configreference/system.applicationhost/sites/site/application/virtualdirectory 编辑:此链接提供了设置所需的信息: https : //www.iis.net/configreference/system.applicationhost/sites/site/application/virtualdirectory

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

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