0
votes

I am in the process of finishing up working on a web API application that is to be used for an android app. Unfortunately, my main website uses asp.net membership database.

I added the old asp.net membership code from my web form program in the Web API to create new users within the membership database and to retrieve the USERID from the newly created entry. This does not work, however. I thought it would work since I did not get any error indicating it would not when the code was added like I did when I added the Profile Common code.

My question are:

  1. Will I need to upgrade my old membership to Identity? (Not ideal).
  2. Can the asp.net membership database be used with web api? Any examples?

        Dim status As MembershipCreateStatus
    
        If Membership.GetUser(newMember.Username) Is Nothing Then
    
            Membership.CreateUser(newMember.Username, Hash(Password), newMember.Email, "None", "None", True, status)
    
        End If
    
    Catch ex As Exception        
    
    End Try
    
    Try
        FormsAuthentication.SetAuthCookie(newMember.Username, True)
    Catch ex As Exception        
    
    
    End Try
    
    Try
    
        Dim mbr As MembershipUser = Membership.GetUser(newMember.Username)
        Membership.UpdateUser(mbr)
        userGUID = mbr.ProviderUserKey
    
    Catch ex As Exception           
    
    End Try
    
    Try
        If Not Roles.IsUserInRole(newMember.Username, "member") Then
            Roles.AddUserToRole(newMember.Username, "member")
        End If
    Catch ex As Exception
    
    End Try
    Return userGUID
    
1
You will need to edit your question and include the code that doesn't work, because ASP.NET Web API runs on ASP.NET so it fully supports membership - Camilo Terevinto
@CamiloTerevinto Added code. Thanks. - Blackie

1 Answers

0
votes

Problem solved. The issue was that I needed to use user id and password in the connection string.