如何检测 ASP.NET 中位置所需的角色?

发布于 2024-11-27 04:35:05 字数 545 浏览 1 评论 0 原文

我正在开发一个 ASP.NET 授权模块,到目前为止,它在与 MVC 应用程序一起使用时工作得很好。

然而,我的要求之一是它也必须与普通的旧 ASP.NET 应用程序一起工作。

为此,我需要检测用户访问任意 URL 所需的角色。

例如,假设我们在 web.config 中:

<location path="foo">
  <system.web>
    <authorization>
      <deny user="?"/>
      <allow role="bar, superFoo"/>
    </authorization>
  </system.web>
</location>

除了自己读取 web.config 之外,我如何检测路径 foo 需要角色 bar 和 <代码>superFoo?

我正在通过 IHttpModule 接口的实现来检查角色要求。

I'm developing an ASP.NET authorization module, and so far it works beautifully when using with MVC applications.

However, one of my requirements is that it must work with plain old ASP.NET applications too.

In order to do so, I need to detect what are the required roles that a user must have to access an arbitrary URL.

For instance, imagine that we have in the web.config:

<location path="foo">
  <system.web>
    <authorization>
      <deny user="?"/>
      <allow role="bar, superFoo"/>
    </authorization>
  </system.web>
</location>

Other than reading the web.config myself, how can I detect that the path foo requires the roles bar and superFoo?

I'm checking the roles requirement through an implementation of the IHttpModule interface.

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

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

发布评论

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

评论(2

回眸一遍 2024-12-04 04:35:06

对于 ASP.NET Web 表单应用程序,您必须调用 Roles 类中的 GetRolesForUser()IsUserInRole(String) 方法来查看用户是否是在角色中。

For a ASP.NET web forms application You have to call GetRolesForUser() or IsUserInRole(String) methods in Roles class to see if the user is in the roles.

jJeQQOZ5 2024-12-04 04:35:05

您可以使用 UrlAuthorizationModule.CheckUrlAccessForPrincipal

CheckUrlAccessForPrincipal 方法检查是否
当前用户被授予访问 Web.config 中请求的文件的权限
应用程序文件。

You can check ability of access to path by using UrlAuthorizationModule.CheckUrlAccessForPrincipal.

The CheckUrlAccessForPrincipal method checks to see whether the
current user is granted access to the requested file in the Web.config
file for the application.

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