开发者

Providing links to files outside of IIS

I have an upload function in my system that stores the files on the d drive e.g D:\KBFiles. Now i need to offer these files as links through internet explorer. Obviously i cant just off开发者_如何学Pythoner a path e.g D:\KBFiles\test.pdf. Whats the best way to handle this scenario


Write "proxy" file with such code and call it DownloadFile.aspx:

string fileName = Request.QueryString["file"];
string filePath = Path.Combime("D:\\KBFile", fileName);
Response.WriteFile(filePath);

Then have such link:

<a href="DownloadFile.aspx?file=test.pdf">test.pdf</a>

This allows you to check the user permissions if you're using Login system and also you can check the requested file against some white list to prevent hacking attempts.


You need to create a Virtual Folder for that windows folder inside your WebApplication. As soon as IIS has mapped the virtual folder, it would be possible to use direct links, which would have your WebApplication as a root.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜