如何在库 dll 中使用 ASP.NET 成员身份中的 IsInRole

发布于 2024-08-15 15:56:54 字数 159 浏览 0 评论 0原文

大多数现实世界的 Web 应用程序背后至少有一个 dll 库。如果我们使用 ASP.NET 成员资格提供程序,我们如何调用 dll 中的 Roles.IsInRole 方法?

引用HttpContext的可能性不太好。因为,我们有一些控制台应用程序工具使用相同的dll来完成一些批量操作。

Most Real world web applications have at least one dll library behind them. If we use the ASP.NET membership provider, how can we call the Roles.IsInRole method in the dll?

The possibility of referencing HttpContext is not good. Because, we have a few console application tools that use the same dll to complete a few bulk operations.

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

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

发布评论

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

评论(1

戏舞 2024-08-22 15:56:55

听起来您需要将您的会员机制与 ASP.NET 分离。

这里提供了一些关于如何引用 ASP 的好资源来自 Windows 窗体应用程序的 .NET 成员资格提供程序,其工作方式与控制台应用程序相同。

最好的一个是此处(在 VB.NET 中)。

然而,所有这些都面临着相同的基本问题,即恶意用户可以更改其配置以使用自己的授权数据库。 (ASP.NET 配置对用户不可用,因此我们不会遇到同样的问题。)

因此,更好的方法是直接从 ADO.NET 中的代码查询 ASP.NET 成员数据库(这不是很难:它们相当简单)或滚动您自己的底层成员资格提供程序接口的实现(MSDN 上的详细信息 此处)。然后,您可以让 ASP.NET 成员资格提供程序调用您自己的代码来确定用户是否处于某个角色中,并在控制台应用程序中以相同的方式使用此代码。

It sounds like you need to decouple your Membership mechanism from ASP.NET.

There are some good resources here on how to reference the ASP.NET Membership Provider from Windows Forms applications, which would work in the same way for console applications.

The best one is here (in VB.NET).

However, all suffer the same basic problem, which is that a malicious user could change their configuration to use their own authorisation database. (ASP.NET configuration is not available to users so we don't have the same problem there.)

So a better approach would be to either directly query the ASP.NET membership databases from your code in ADO.NET (which isn't hard: they're fairly straightforward) or to roll your own implementation of the underlying Membership Provider interfaces (detailer on MSDN here). You could then have the ASP.NET Membership Provider call your own code to establish if a user is in a role, and use this code in the same way from your console application.

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