通过键入URL来防止直接访问文件夹文件
IIS上有一个ASP.NET WebForm应用程序。项目文件夹中有PDF和图像文件,称为上传。
可以通过Web应用程序中的链接访问上传文件夹中的这些文件。用户正在通过数据库中存储的用户名和密码进行身份验证。
任何人都可以通过在浏览器中键入URL(示例:https // myapplication.com/uploads/uploads/uploads/uploads.pdf)来访问PDF和图像文件,而无需登录系统。
有没有办法限制URL,以便只登录用户才能访问它们?
我试图拒绝文件夹上的iusr用户的读取访问,但它停止登录用户以查看文件。
There is a asp.net webform application hosted on IIS. There are pdf and image files in the project folder called upload.
Those files in the upload folder can be accessed through the link in the web application. Users are being Authenticated via username and password which are stored in the database.
Anyone can access the pdf and image files by typing the URL (example: https//myapplication.com/uploads/11%20pics.pdf) in the browser without logging into the system.
Is there a way to restrict the URL so that only logged in users can access them?
I have tried to Deny the Read access for IUSR user on the folder but it stops logged in users to view the file.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
实际上,这是一种简单的方法?
既然您永远不希望任何用户或任何人输入该URL?
然后只需在该文件夹上使用Internet安全设置即可。请记住,背后的代码不使用基于Web的URL,更重要的是也不尊重IIS(基于Web的)URL安全设置!!!
后面的代码始终使用Jane简单的Windows文件名。
您可以尝试弄乱Actaul文件夹权利,但您确实不需要。
您要做的就是使用基于Web的Secuirty设置“拒绝”所有用户。您可以通过将Web配置文件放入与UploadFiles文件夹相同的文件夹中来轻松执行此操作。
因此,只需像您这样做的那样放入Web配置中,以根据所示角色保护所有文件夹,然后在此删除:
因此,现在,如果有人尝试输入URL,则将被拒绝访问该文件夹。
但是,您背后的代码不在乎,不使用,并且对URL的代码很明显,并且您使用的IIS Security(web.config)文件。
您的代码在100%背后忽略了登录权,包括角色模因等。
因此,在后面的代码中,我仍然可以自由打开 +阅读,并做任何事情。
但是,您没有提及那些假设的“链接”。因为如果我们从所有用户中保护该文件夹,那么用户当然不能使用超级链接。
但是,这并不是什么大不了的,因为如果您在数据库中驱动上加载的文件 - 用户说,然后代替“链接”下载文件,只需读取并将文件读取给用户。
因此,说我们有:
我不知道您是仅保存文件名还是数据库中的整个路径名。
但是,这样说一个简单的网格:
然后说这样的负载:
我们现在有这样的加载:
因此,我们不使用超链接进行下载。
我们从该数据库获取文件名 - 。
说,就像这个网格视图行的“对接点击事件”
,因此,现在我们可以防止URL - 实际上,甚至不必揭露我们将文件藏起来的位置。我们只显示文件名,但是路径名和文件夹?永远不会暴露。
当然,您将根据“用户ID”或其他类似内容加载文件网格。
并请注意,您确实必须包括“矿山”映射类型。这确实需要.NET 4.5或更高版本。
(或者您可以保存在数据库列中)。
Actually, a much simple way to do this?
since you NEVER want any user or anyone to type in that URL?
Then just use internet security settings on that folder. Remember, code behind does NOT use the web based URL's, and MORE important does not respect the IIS (web based) URL security settings either!!!
Code behind always uses plane jane simple windows file names.
You can try and mess around with actaul folder rights, but you really don't need to.
All you have to do is "deny" any and all users by using the Web based secuirty settings. You can easy do that by dropping in a web config file into the same folder as the UpLoadFiles folder.
Hence, just drop in a web config like you do to secure all folders based on say role, and drop in this:
So, now, if any one try's to type in a url - they will be denied access to that folder.
but, your code behind does NOT care, does NOT use, and is obvious to the URL's and that IIS security (web.config) file you use.
Your code behind 100% ignores the logon rights - including role memebership etc.
So, in code behind, I can still freely open + read, and do whatever.
However, you don't mention how those supposed "links" you have. Since if we secure that folder from all users, then of course users can't use a hyper link.
but, that's not really a big deal, since if you driving the up-loaded files in a database - say by users, then in place of say a "link" to download the file, just read and stream out the file to the user.
So, say we have this:
I don't know if you save JUST the file name, or the whole path name in the database.
But, say a simple grid like this:
And say load up like this:
And we now have this:
So, we do NOT use a hyper-link for the download.
We fetch the file name - from that database.
Say, like this buttion click event for the grid view row
So, now we prevent url's - and in fact NEVER have to even expose where we tucked away the files. We only ever display the file name, but the path name and folder? Never exposed.
Of course, you would load the grid of files based on "user id" or some such.
And note that you DO have to include the "mine" mapping type. This does require .net 4.5 or later.
(or you can save the mine type in a database column).