将 ASP.net 成员资格提供程序移至单独的类库
我正在构建一个具有非常基本的身份验证的 MVC 2 应用程序(一个用户和角色来访问管理部分)。因为在我开始项目时内置了一些基本的表单身份验证,所以我只是使用它。问题是,我已经开始将所有数据访问代码移动到一个单独的项目(类库),并且我不确定如何在不破坏所有内容的情况下移动成员资格提供程序的内容。我不想将其与其他代码一起保留,但当存在足够的提供程序时,我也不想花几个小时来滚动我自己的提供程序。
那么,是否可以将内置的 ASP.NET 会员资格提供程序代码移至单独的类库项目中?如果是这样,怎么办。如果没有,我有什么选择?
I'm building an MVC 2 app with very basic authentication (one user and role to access admin sections). Because some basic forms authentication was built in when I started my project, I just used that. The problem is, I've started moving all of my data access code to a separate project (class library), and I'm not sure how to move the membership provider stuff without breaking everything. I'd rather not leave it with the other code, but I also don't wanna spend hours rolling my own provider when a sufficient one exists.
So, is it possible to move the built-in asp.net membership provider code to a separate class library project? If so, how. If not, what are my options?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
内置的 asp.net 提供程序仅适用于配置设置和数据库设置。您不必为其编写大量代码。如果您指的是如何在代码中调用其方法,例如(getUser() 或 validateUser() 等..),那么您可以很好地引用类库中所需的 DLL 并将代码移动到那里。
The built-in asp.net provider works with just config settings and DB setup. You don't have to write whole lot of code for it. If you are referring to how its methods are called within your code like (getUser() or validateUser() etc..) then you can very well reference the required DLLs in the class library and move the code there.
如果您尝试使用类库,则必须引用 System.Web 和 System.Web.ApplicationServices
If you are trying to use a class library you'll have to reference System.Web and System.Web.ApplicationServices
对于我自己来说,我使用封装 Membership 类的 AuthenticationService 类,因此可以更轻松地对我的控制器进行单元测试,也更容易将我的类移动到我想要的位置。在我的控制器中,我有一个 IAuthentificationService ,它位于控制器的构造函数中(来自 DI)。如果您想从 Asp.Net 会员资格切换到其他“安全提供商”,这也会更容易。
For myself I'm using a AuthenticationService class that encapsulate the Membership class, so it's easyer to unit test my controller and also easier to move my class where I want to. In my controller I have a IAuthentificationService that is past in the controller's constructor (from DI). It's also easier if you want to switch from Asp.Net membership to an other "security provider".