SimpleMembershipProvider vs WebSecurity

I have a WebAPI project with a Repository layer. For methods related to accounts, I'm not sure which method to use here:

public class RepositoryService : IRepositoryService
    {
        private readonly SimpleMembershipProvider _membership;
        public RepositoryService()
          {
            _membership = (SimpleMembershipProvider)Membership.Provider;
          }

To check if a user exists:

    public bool UserExists(string userName)
    {
        return WebSecurity.UserExists(userName);
    }

OR

public bool UserExists(string userName)
{
    return _membership.GetUser(userName, true) != null;
}

I'm wondering because in other places I think I have to use _membership (to get a specific user, for example):

public MembershipUser GetUser(string userName)
    {
        return _membership.GetUser(userName, false);
    }

But it seems odd that I have to use _membership and WebSecurity. Is there anything "smelly" about using both?

Answers


The following seems to suggests that you are OK:

From the MSDN docs http://msdn.microsoft.com/en-us/library/gg547905%28v=vs.111%29.aspx on the WebSecurity class:

Behind the scenes, the WebSecurity class interacts with an ASP.NET membership provider that in turn performs the lower-level work that is required in order to perform security tasks. The default membership provider in ASP.NET Web Pages is the SimpleMembershipProvider class.


Need Your Help

Return Multiple Collections for use in an MVC4 asp.net View page

razor asp.net-mvc-4

I understand how to return a single collection (List<>) from a controller by returning View({mylist}); then referencing that with razor syntax @Model etc. inside the view page. In my case, I have

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.