如何实现 ASP.NET 角色提供程序?

发布于 2024-10-26 05:14:58 字数 614 浏览 1 评论 0原文

我有一些关于 ASP.NET 成员资格和角色提供程序的顶级问题。我做了一些搜索,但很难找到一些外行教程。我已经在 ASP.NET 中编码了一段时间,但我在身份验证方面唯一的真实经验是使用 FormsAuthentication.SetAuthCookie(usernameFromDatabase, false);

当我使用 SetAuthCookie( ) 上面的方法我使用的是 ASP.NET Membership Provider 吗?如果我错了请纠正我,但我不认为我是。我只是设置了一个身份验证cookie,对吗?我通常在数据存储库中实现自己的自定义方法,例如 GetUser_ByUsername(string username),然后与 ORM 对话并获取正确的用户。

  1. 成员资格和角色提供者是否有自己的数据存储?
  2. 如果我想使用自己的数据存储怎么办?
  3. 我是否需要实现自己的会员资格/角色提供者,以及如何做到这一点?
  4. 或者我只是设置身份验证 cookie,然后使用我自己的检索方法等,这是进行自定义成员资格/角色提供程序的最佳方法吗?

我只是在寻找该系统的简短教程/解释。如果您有任何好的参考资料供我参考,我会很乐意看一下:)

I've got a few top-level questions about ASP.NET Membership and Role providers. I've done some searching but am having a hard time finding some layman tutorials. I have been coding in ASP.NET for a while now but the only real experience I have with authentication is the use of FormsAuthentication.SetAuthCookie(usernameFromDatabase, false);

When I use the SetAuthCookie() method above am I using the ASP.NET Membership Provider? Correct me if I'm wrong please but I don't think I am. I am just setting an authentication cookie right? I usually implement my own custom methods in my data repositories like GetUser_ByUsername(string username) which then talks to the ORM and gets the right user.

  1. Do the Membership and Role Providers have their own data storage?
  2. What if I want to use my own data storage?
  3. Do I need to implement my own membership/role provider, and how would one go about doing that?
  4. Or is my way of just setting the auth cookie and then using my own retrieval methods, etc, the best way of doing a custom membership/role provider?

I'm just looking for a brief tutorial/explanation of this system. If you have any good references for me to look at I will happily take a look :)

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

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

发布评论

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

评论(3

┈┾☆殇 2024-11-02 05:14:58

实施会员服务提供商并不太难。请注意,您只需要实现您计划实际使用的方法。会员资格提供商应被视为从身份验证角度与您的用户信息进行交互的一种手段。它不会为您创建 auth cookie;您可以在成功调用提供程序上的 ValidateUser 方法后执行此操作。它将允许您针对提供程序接口开发应用程序,并通过配置轻松更改要使用的提供程序,而不是重写应用程序代码。我使用自己的架构成功实现了多个不同的成员资格提供程序,这些提供程序支持内置和混合内置/活动目录身份验证。可通过以下链接获取更多信息:

Implementing a membership provider is not too hard. Note that you only need to implement the methods that you plan to actually use. The membership provider should be viewed as a means to interact with your user information from an authentication perspective. It won't create the auth cookie for you; you do that after a successful call to the ValidateUser method on the provider. It will allow you to develop an application against the provider interface and easily change which provider you want to use via configuration rather than rewriting the application code. I've successfully implemented several different membership providers, using my own schema, which support built-in and hybrid built-in/active directory authentication. More info available via the links below:

娇俏 2024-11-02 05:14:58

SetAuthCookie() 与 ASP.NET 中的表单身份验证框架配合使用,然后您可以对其进行调整以与会员资格提供程序集成。

  • 成员资格和角色提供者是否有自己的数据存储?

他们可以,是的。有一个抽象实现,您可以根据您的特定数据需求对其进行子类化。您可以直接使用一个SqlMembershipProvider,您只需要一个数据库来指向并创建所需的表。关于该类有很多信息,例如这里此处< /a>.

  • 如果我想使用自己的数据存储怎么办?

SqlMembershipProvider 可以,但请查看这个替代 MySQL 框架如果您有兴趣了解另一个 DBMS 是如何做到这一点的。

  • 我是否需要实现自己的会员资格/角色提供者,以及如何做到这一点?

使用内置的桌子非常容易,但许多商店都推出自己的桌子,以便他们可以使用现有的桌子。您需要实现此类

  • 或者我只是设置身份验证 cookie,然后使用我自己的检索方法等,这是进行自定义成员资格/角色提供程序的最佳方法吗?

您很可能需要一个更强大的系统,而自定义会员资格提供商是一个好主意。

SetAuthCookie() works with the Forms Authentication framework within ASP.NET which you can then adapt for integration with a membership provider.

  • Do the Membership and Role Providers have their own data storage?

They can, yes. There is an abstract implementation that you can subclass for your specific data needs. There is a SqlMembershipProvider you can use right out of the box, you just need a database to point to and create the needed tables. There is quite a bit of information on that class, like here or here.

  • What if I want to use my own data storage?

The SqlMembershipProvider does, but check out this alternative MySQL framework if you're interested in seeing how another DBMS does it.

  • Do I need to implement my own membership/role provider, and how would one go about doing that?

Using the built-in ones is pretty easy, but a lot of shops roll their own so that they can use existing tables. You'll need to implement this class.

  • Or is my way of just setting the auth cookie and then using my own retrieval methods, etc, the best way of doing a custom membership/role provider?

In all likelihood you'll need a stronger system, and a custom membership provider is a good idea.

相思故 2024-11-02 05:14:58

1 - 是的,如果您使用内置的成员资格/角色提供程序,它们将使用在单独的数据库或现有数据库中创建的表。您可以使用工具 aspnet_regsql.exe 创建这些表 - 它会引导您完成向导。或者,也可以使用不同的参数从命令行调用它以跳过向导。 是来自 MS 的有关在您的计算机中创建必要的数据库/表的一些信息数据库。

2 - 您可以这样做,但您必须实现自定义会员资格提供程序,这并不困难。 此处这里是一些教程。

3 - 您不一定需要,除非您想使用自己的数据存储,或者您需要内置提供程序中不存在的功能。

4 - 我想说您最好使用 ASP.NET 为成员资格和角色提供的内置功能。

1 - Yes, if you use the built in membership/role providers they use tables created either in a separate database or an existing one. You use the tool aspnet_regsql.exe to create these tables - it walks you through a wizard. Alternatively, it can also be called from the command-line with different arguments in order to skip the wizard. This is some info from MS about creating the necessary DB/tables within your DB.

2 - You can do that, but you have to implement a custom membership provider, which isn't really difficult. Here and here are some tutorials.

3 - You don't necessarily need to unless you either want to use your own data stores or you need functionality from it that isn't present in the built-in providers.

4 - I would say you're better off using the built-in functionality ASP.NET provides for membership and roles.

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