0

I'm trying to implement a customer ASP.NET Membership provider. I have no database yet, but I know I want one that's simple and accessible.

I know I don't want to use the generated tables because from what I've seen and understand, they are very convoluted and include many fields that I just won't need. I set up the default Membership provider and let it generate its own database/tables and it produced this:

enter image description here

All by itself. I don't want this mess as part of my database. So the natural solution? A custom membership provider. To do this, I know you need to inherit from System.Web.Security.MembershipProvider and setup web.config to the derived class that I create.

public class MessAround : System.Web.Security.MembershipProvider
{
public MessAround()
{

    //
    // TODO: Add constructor logic here
    //
}

public override string ApplicationName
{
    get
    {
        throw new NotImplementedException();
    }
    set
    {
        throw new NotImplementedException();
    }
}

public override bool ChangePassword(string username, string oldPassword,

 string newPassword)
{
    throw new NotImplementedException();
}

public override bool ChangePasswordQuestionAndAnswer(string username
, string password, string newPasswordQuestion, string newPasswordAnswer)
{
    throw new NotImplementedException();
}

....ETC ETC ETC

My question is:

  • How do I integrate this class into a custom database schema?

  • How do I eliminate fields that I don't need?

  • How do I get this class to interact with my database tables?

  • WTF is going on? :P

John Saunders
  • 160,644
  • 26
  • 247
  • 397
user3308043
  • 797
  • 2
  • 9
  • 20
  • In the generate class, just remove `throw new NotImplementedException();` from the methods you will use and instead add you own implementaion in them. Those methods you will not need you can leave as is with the throw. Check this answer to get started: http://stackoverflow.com/a/5702000/1429080 – user1429080 May 22 '14 at 09:47

1 Answers1

1

First of all, The whole ASP.Net Membership is inbuilt functionality. So there is pros and cons comes as

Pros

  • easy to use and implement
  • give all functionality of user management
  • automatically create UI, DB and relationship.

Cons

  • customization is tedious job.
  • after implementation to whole systam, to remove whole thing will make issue.

Now I give the answer one by one.

  1. How do I integrate this class into a custom database schema? For schema use, the rule is always use schema-name before object like yourschema.sp_name
  2. How do I eliminate fields that I don't need? You can't remove fields as one or more reference of fields. Why you remove fields, you just left that. I also found the same issue, in that I left and only use which I want.
  3. How do I get this class to interact with my database tables? If you are using Entity-Framenwork or linq, its get as a class of your table. Which type of interact you need? for login- logout or session management. Then check this link:

How to Check whether Session is Expired or not in asp.net

Using session variable with ASP.Net membership provider

Community
  • 1
  • 1
Ajay2707
  • 5,690
  • 6
  • 40
  • 58
  • "You can't remove fields as one or more reference of fields. Why you remove fields, you just left that. I also found the same issue, in that I left and only use which I want." Please elaborate. – user3308043 May 22 '14 at 05:35
  • My suggestion is use membership table as it is. You just add your custom table in case you wish to need something. Remove column in membership table is give some time error for reference-key or other, becuase all are related to each other. So don't waste the time to remove. Just do what you needed. – Ajay2707 May 22 '14 at 05:51
  • I'd have to say that I don't necessarily agree and neither does most of the web, because custom Membership providers are often recommended. The point is, I don't *want* to use that database schema. Take a look at this article, it may be the real solution here. – user3308043 May 22 '14 at 05:57
  • While I appreciate you taking the time to answer very much, I wasn't looking for somebody to say "Just use the default, it's better" – user3308043 May 22 '14 at 06:11