简体   繁体   English

如何在不显示物理路径的情况下显示文件夹中的文件?

[英]How to display a file in a folder without showing physical path?

I use .NET Framework.我使用.NET 框架。 I have a files in a folder.我在一个文件夹中有一个文件。 Physical path like:物理路径如:

https://example.com/folders/123aaa.jpg

And I have a button to redirect this link.我有一个按钮可以重定向此链接。 But I don't want to show this path.但我不想展示这条道路。 I want user to see like:我希望用户看到:

https://example.com/display.aspx

Is there any way to do that?有没有办法做到这一点?

<asp:Button ID="eg" runat="server" CausesValidation="false" CommandName="Save"

private void save(int i)
{
    GridViewRow row = GridView7.Rows[i];
    string sid = row.Cells[0].Text;
    SqlCommand cmd = new SqlCommand("xxx", con);
    cmd.CommandType = System.Data.CommandType.StoredProcedure;
    cmd.Parameters.AddWithValue("@id", sid);         
    con.Open();
    SqlDataReader rd = cmd.ExecuteReader();
    if (rd.HasRows)
    {
        while (rd.Read())
        {
            string url = rd[0].ToString();
        }
    }

    Response.Redirect(url,false); 
}

No, your client has to send some form of identifier.不,您的客户必须发送某种形式的标识符。 Otherwise, how will your server know which file they requested?否则,您的服务器如何知道他们请求的是哪个文件? And any identifier that an browser sends, can be inspected by the user.浏览器发送的任何标识符都可以由用户检查。

So you're trying to apply security through obscurity.所以你试图通过默默无闻来应用安全性。

If you don't want clients to know the folder name folders , or the file name 123aaa.jpg , you'll have to obscure this through a mapping, for example a large random name that maps to the actual file path.如果您不希望客户端知道文件夹名称folders或文件名123aaa.jpg ,则必须通过映射来掩盖它,例如映射到实际文件路径的大随机名称。

You can do this by for example saving the random names and actual paths in a database, and create a handler that looks up the file:例如,您可以通过将随机名称和实际路径保存在数据库中,并创建一个查找文件的处理程序来执行此操作:

/images.ashx?file=abc-123-456

Then that ASHX handler looks up the file with the name abc-123-456 in the database, and writes the actual file to the response.然后该 ASHX 处理程序在数据库中查找名为abc-123-456的文件,并将实际文件写入响应。

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

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