Listing files available for download - files are stored in location accessible to the application only

心已入冬 提交于 2019-12-06 11:09:23

With regular ASP.NET (2.0) you would want to create a "handler". The easiest option is to add a "generic handler" (ashx) template - then put a regular link on the page to (for example) "download.ashx?id=2".

Inside the handler, parse the query-string, and stream the file to the user:

    public void ProcessRequest(HttpContext context)
    {
        // set headers...
        string filePath = FindPath(context.Request.QueryString("id"));
        context.Response.WriteFile(filePath);
    }

where FindPath resolves the physical file from the query-string link.

If this was ASP.NET MVC, you could just use the File(path) action-result.

The URLs in the list of files your return to the user can point to an ASPX page that can download them just like in the example code you provided.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!