开发者

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!

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.

开发者_运维知识库

I know how to implement custom provider, I just want to know if I have more tedious work implementing functionality from other Membership* classes.


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.davidhayden.com/blog/dave/archive/2007/10/11/CreateCustomMembershipProviderASPNETWebsiteSecurity.aspx
http://www.shiningstar.net/aspnet_articles/customprovider/CustomProvider.aspx
http://www.devx.com/asp/Article/29256/0/page/3
http://www.15seconds.com/issue/050216.htm
http://www.codeproject.com/KB/aspnet/CustomMembershipProviders.aspx
http://www.codeproject.com/KB/aspnet/WSSecurityProvider.aspx


You don't need to implement the full MembershipProvider. Just implement the bits you need, and for the other unused methods throw a 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);
} 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜