简体   繁体   English

自定义成员资格提供者和MembershipUser

[英]Custom Membership Provider and MembershipUser

I have simple question. 我有一个简单的问题。 I'm now thinking about creating custom membership provider for my app, because using separate tables for membership and for rest of the app is not that good idea.. not to mention some data is simply replicated along tables.. 我现在正在考虑为我的应用程序创建自定义成员资格提供程序,因为使用单独的表来获取成员资格以及应用程序的其余部分并不是一个好主意。更不用说一些数据只是沿着表复制了..

What I want to know, if I also have to reimplement other functionaly like checking if user is online, and so on. 我想知道的是,如果我还需要重新实现其他功能,例如检查用户是否在线,等等。 Or it's just enough if i copy part of db structure and implement provider ? 或者,如果我复制部分数据库结构并实现提供程序,那就足够了?

UPDATE! UPDATE!

What I really want to know is the methods from MembershipUser (like checking IF user IsOnline and so on), will work on custom database schema. 我真正想知道的是来自MembershipUser的方法(比如检查IF用户IsOnline等),将使用自定义数据库模式。

I know how to implement custom provider, I just want to know if I have more tedious work implementing functionality from other Membership* classes. 我知道如何实现自定义提供程序,我只想知道我是否有更多繁琐的工作来实现其他Membership *类的功能。

Separate Tables for membership and for rest of the app is not a good idea? 对于成员资格和应用程序的其余部分,单独的表不是一个好主意? It has to be in a different table. 必须在不同的表格中。 Maybe you meant separate databases . 也许你的意思是单独的数据
Any way, you do not need to impolement all methods. 无论如何,你不需要任何方法。 Here are the necessary methods you have to implement: 以下是您必须实现的必要方法:

public class CustomMembershipProvider : MembershipProvider
{   
  public override MembershipUser CreateUser(string username, 
     string password, string email, string passwordQuestion, 
     string passwordAnswer, bool isApproved, 
     object providerUserKey, out MembershipCreateStatus status)
  {
      throw new NotImplementedException();
  }

  public override MembershipUser GetUser(string username, bool userIsOnline)
  {
      throw new NotImplementedException();
  }

  public override bool ValidateUser(string username, string password)
  {
      throw new NotImplementedException();
  }

  public override int MinRequiredPasswordLength
  {
      get { throw new NotImplementedException(); }
  }

  public override bool RequiresUniqueEmail
  {
      get { throw new NotImplementedException(); }
  }
}  

You can find dozens of examples on the net. 你可以在网上找到几十个例子。 Some are: 有些是:
http://www.asp.net/general/videos/how-do-i-create-a-custom-membership-provider http://www.asp.net/general/videos/how-do-i-create-a-custom-membership-provider
http://www.davidhayden.com/blog/dave/archive/2007/10/11/CreateCustomMembershipProviderASPNETWebsiteSecurity.aspx http://www.davidhayden.com/blog/dave/archive/2007/10/11/CreateCustomMembershipProviderASPNETWebsiteSecurity.aspx
http://www.shiningstar.net/aspnet_articles/customprovider/CustomProvider.aspx http://www.shiningstar.net/aspnet_articles/customprovider/CustomProvider.aspx
http://www.devx.com/asp/Article/29256/0/page/3 http://www.devx.com/asp/Article/29256/0/page/3
http://www.15seconds.com/issue/050216.htm http://www.15seconds.com/issue/050216.htm
http://www.codeproject.com/KB/aspnet/CustomMembershipProviders.aspx http://www.codeproject.com/KB/aspnet/CustomMembershipProviders.aspx
http://www.codeproject.com/KB/aspnet/WSSecurityProvider.aspx http://www.codeproject.com/KB/aspnet/WSSecurityProvider.aspx

You don't need to implement the full MembershipProvider. 您不需要实现完整的MembershipProvider。 Just implement the bits you need, and for the other unused methods throw a NotImplementedException . 只需实现您需要的位,并为其他未使用的方法抛出NotImplementedException

What's the best approach if I have some overriden methods that really just need to behave the same as the abstract method? 如果我有一些真正需要与抽象方法相同的重写方法,那么最好的方法是什么?

Example. 例。

public override bool ValidateUser(string username, string password) 
{ 
//      This won't work but I need something like this      
        return Membership.ValidateUser(username, password);
} 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM