ASP.net 中的静态文件和身份验证

发布于 2024-07-14 07:59:09 字数 622 浏览 7 评论 0原文

假设我在 IIS7 中有一个虚拟文件夹 /topFolder/,并且在该文件夹中可以有任何可以在浏览器中显示的文件(xml、html、swf、doc 等 - 从 IIS 角度来看通常是“非托管”资源)。 在授予请求打开文件夹下任何文件的权限之前,我需要检查一些会话变量,以查看用户是否拥有相关子文件夹和文件的“许可证”。

我尝试使用 IHttpModule 和 IReadOnlySessionState 接口实现模块,但是当文件是“静态”且不是 IIS 管理的(如 aspx、ashx 等)时,AcquireRequestState 事件上的 Session 始终为 null。

如果我使用自定义 HttpHandler,我会获取会话,但我还需要实现如何将内容发送到响应。 编辑:由于用户没有下载该文件,我只希望 IIS 提供该文件,就像使用其 StaticFileModule 一样。 处理程序/模块实际上应该是 StaticFileModuleWithAuthorizationHook...

所以我真的想做以下事情: 1. 对于请求 /topFolder/* :检查会话和许可证等 a) 如果没问题,继续提供文件 b) 如果不正常,则中断请求,或者仅发送 FORBIDDEN 作为响应。

希望有人能帮忙。

Say I have a virtual folder /topFolder/ in IIS7, and in that folder there can be any file that can be displayed in a browser (xml, html, swf, doc etc - typically "unmanaged" resources from the IIS perspective).
Before giving the request permission to open any file below the folder, I need to check some session variables in order to see if the user has a "license" for the subfolder and file in question.

I've tried implementing a module with IHttpModule and IReadOnlySessionState interfaces, but the Session is always null on the AcquireRequestState event when the file is "static" and not IIS managed (like aspx, ashx etc).

If I use a custom HttpHandler, I get the session, but then I also need to implement how the content is sent to response. Edit: Since the user isn't downloading the file, I just want IIS to serve the file like it does with its StaticFileModule. The Handler/Module should really be a StaticFileModuleWithAuthorizationHook...

So I really want to do the following:
1. For request /topFolder/* : check session and licenses etc
a) If ok, continue serving file
b) If not ok, interrupt request, or just send FORBIDDEN in response.

Hope someone can help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

奢欲 2024-07-21 07:59:09

您应该能够通过 httphandler 处理此问题,简单的方法是使用内置方法将文件发送给用户(如果他们有权访问)。

本文(位于底部)显示了一个示例如何做到这一点。

You should be able to handle this via the httphandler, the simple way is to use the built in methods to send the file down to the user if they have access.

This article (at the bottom) shows an example of how to do this.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文