一种方法,以避免在MVC认证的供应商类派生供应商、方法、以避免、MVC

2023-09-06 14:07:30 作者:太过苛刻.

寻找在MVC我很遗憾没有找到明确的答案,我的问题的最佳实践进行验证。这个问题的思考我试着去想象一些原则,可能是在我的设计中非常有用。 好了,

Looking for the best practice for authentication in MVC I unfortunately didn't find the clear answer to my question. Thinking of the problem I tried to imagine some principles that could be useful in my design. Well,

我想用一个基AccountController类 我想将所有的表,如用户,角色,权限等成我自己的数据库。但我不希望执行的标准ASPNETDB设计(可轻松获得通过aspnet_regsql)

所以,主要的问题是我能做到这一点没有得出抽象类一样的MembershipProvider,RoleProvider等?我将preFER不能做的就是实现从这些类的所有抽象方法。

So the main question is can I do this without deriving abstract classes like MembershipProvider, RoleProvider etc? What I would prefer not to do is implement all the abstract methods from these classes.

第二个问题仍然是有关认证如最佳实践对于小项目,对路数?

The second question is still about the best practice for authentication e.g. for the small projects, for the large ones?

推荐答案

您可以真正获得最大的工作没有实施的MembershipProvider和RoleProvider每一个方法的基本需要的功能

You can actually get most of the basic required functionality working without implementing every method in MembershipProvider and RoleProvider

只需使用抛出新的NotImplementedException(); 的属性/方法,你不打算用身体

Just use throw new NotImplementedException(); as the body of properties/methods you aren't going to use.

我的自定义成员提供程序只提供了真正的实现了。

My custom membership provider just provides real implementations for

布尔的ChangePassword(用户名字符串,字符串旧密码,串新密码) 的MembershipUser的getUser(用户名字符串,布尔userIsOnline) 布尔的ValidateUser(用户名字符串,字符串密码) bool ChangePassword(string username, string oldPassword, string newPassword) MembershipUser GetUser(string username, bool userIsOnline) bool ValidateUser(string username, string password)

抛出新的NotImplementedException(); 为休息

同样,我的自定义角色提供只是工具

Likewise, my custom role provider just implements

的String [] GetRolesForUser(字符串的用户名)

有了这个,我可以使用基本的内置授权和认证,但无太多的努力。

With this I can use the basic built-in authorization and authentication without to much effort.