简体   繁体   中英

Web API using Asp.net membership

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 

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM