自定义会员提供者和会员用户

发布于 2024-11-07 00:00:17 字数 313 浏览 0 评论 0原文

我有一个简单的问题。我现在正在考虑为我的应用程序创建自定义会员资格提供程序,因为对会员资格和应用程序的其余部分使用单独的表并不是一个好主意..更不用说一些数据只是沿着表复制..

我想知道,如果我还必须重新实现其他功能,例如检查用户是否在线等等。或者如果我复制部分数据库结构并实现提供程序就足够了?

更新!

我真正想知道的是 MembershipUser 中的方法(例如检查 IF 用户 IsOnline 等)是否适用于自定义数据库模式。

我知道如何实现自定义提供程序,我只是想知道我是否有更多繁琐的工作来实现其他 Membership* 类的功能。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

北城半夏 2024-11-14 00:00:17

将会员资格表和应用程序的其余部分分开不是一个好主意吗?它必须位于不同的表中。也许您的意思是单独的数据库
无论如何,您不需要实施所有方法。以下是您必须实施的必要方法:

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(); }
  }
}  

您可以在网上找到数十个示例。一些是:
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 /页/3
http://www.15seconds.com/issue/050216.htm
http://www.codeproject.com/KB/aspnet/CustomMembershipProviders.aspx
http://www.codeproject.com/KB/aspnet/WSSecurityProvider.aspx

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

原谅我要高飞 2024-11-14 00:00:17

您不需要实现完整的 MembershipProvider。只需实现您需要的位,而对于其他未使用的方法则抛出 NotImplementedException

You don't need to implement the full MembershipProvider. Just implement the bits you need, and for the other unused methods throw a NotImplementedException.

无声情话 2024-11-14 00:00:17

如果我有一些重写方法,实际上只需要与抽象方法表现相同,那么最好的方法是什么?

例子。

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

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);
} 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文