asp.net - 如何构建和实现自定义成员(member)资格提供商?

标签 asp.net asp.net-mvc-3 asp.net-membership projects-and-solutions membership-provider

我正在尝试学习 ASP.NET MVC。在阅读了网上的许多文章后,我整理了一个粗略的示例应用程序,该应用程序使用自定义成员资格提供程序对现有 SQL 数据库进行身份验证。

我的模型类库项目的结构如下所示。

  • Sigma.Models
    • 实现
      • FormsAuthenticationService.cs
      • MembershipService.cs
    • 接口(interface)
      • IFormsAuthenticationService.cs
      • IMembershipRepository.cs
      • IMembershipService.cs
    • 提供商
      • SigmaMembersipProvider.cs
    • 存储库
      • SqlMembershipRepository.cs
    • MembershipModel.cs

我的问题如下:

  • 我是否应该创建另一个类库项目(例如 Sigma.DataAccess)来单独保存提供程序和存储库?这是一种可以接受的 MVC 解决方案架构方式吗?这只是我正在研究的概念证明,实际项目可能会变得非常庞大。我想确保我从一开始就不会做任何愚蠢的事情。

  • IMembershipRepository 和 IMembershipService 包含大部分相同的功能,只是 IMembershipRepository 使用自定义开发的 MembershipModel 对象返回数据;而 IMembershipService 是标准 ASP.NET MembershipProvider 的接口(interface),并返回 MembershipUser 和 MembershipCollection。我应该让 IMembershipRepository 接口(interface)继承自 IMembershipService 吗?

  • 我希望模型项目可重用,这样我就可以将它用于任何其他 UI 应用程序,例如 WebForms 或 WinForms。项目的结构方式可能吗?

  • 此外,我不想使用 ASP.NET 开箱即用的成员资格提供程序,因为我需要一个可以针对现有数据库工作的解决方案。我认为这意味着我必须自定义 ASP.NET 成员资格提供程序中可用的功能才能针对我的自定义数据库工作。如果我的假设不正确,请纠正我。

提前致谢。

最佳答案

Should I have to create another class library project like Sigma.DataAccess to keep the providers and repositories separately? Is this an acceptable way to do MVC solution architecture? This is only a proof of concept that I am working on and the actual project can get really huge. I want to make sure that I don't do anything stupid to begin with.

是的 - 将它们分开,以防您的实现更改影响较小。

IMembershipRepository and IMembershipService contain mostly the same functionalities except that IMembershipRepository returns data using the custom developed MembershipModel object; whereas IMembershipService is an interface of the standard ASP.NET MembershipProvider and returns MembershipUser and MembershipCollection. Should I have the interface IMembershipRepository inherit from IMembershipService?

实际上,在提供的示例中 - 实际上似乎在实现上没有区别 - 两种方法都是 bool ValidateUser() ,这绝对是重复,但因为它们各自都有一个可能“潜在”改变的最终用途,所以它们被抽象为两个独立的接口(interface),因此我不会让一个接口(interface)继承另一个接口(interface)。

I would like to have models project reusable so I can use it against any other UI applications like WebForms or WinForms. Is that possible with the way project is structured?

是的 - 但我会保留该项目中的模型。任何不是模型的东西都不应该出现在该项目中。

Also, I don't want to use the ASP.NET out-of-the-box membership provider because I need a solution that can work against an existing database. I assume that would mean I have to customize the features available in the ASP.NET membership provider to work against my custom database. Please correct me if my assumption is incorrect.

这是正确的 - 您需要一个自定义 SQL 成员资格提供程序

关于asp.net - 如何构建和实现自定义成员(member)资格提供商?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6090767/

相关文章:

asp.net - 重置 ASP.NET 密码 - 安全问题?

c# - 在没有自动生成模式的情况下使用 MySQL 的成员资格提供程序

asp.net-mvc-3 - MVC3 中单个 MvcContrib.Grid 列中的多个 Html.ActionLink()

c# mvc jquery 实时聊天

asp.net-mvc - ActionLink 显示 URL 中的参数而不是查询字符串?

asp.net-membership - SQL 创建 .Net Membership Provider 用户

c# - Sitecore 语言嵌入多个站点

c# - 获取不在 ASP .NET 列表中的选定单选按钮

asp.net - 如何在 ASP.Net 网络表单中使用标签?

.net - 默认成员(member)提供者的 OnValidatingPassword 是否必须在自定义实现中被覆盖?