For reference here is what my web.config and code look like:
<membership defaultProvider="SqlProvider" userIsOnlineTimeWindow="15">
<providers>
<clear />
<add name="SqlProvider"
type="System.Web.Security.SqlMembershipProvider"
connectionStringName="MySqlConnection"
applicationName="/"
enablePasswordRetrieval="false"
enablePasswordReset="true"
requiresQuestionAndAnswer="false"
requiresUniqueEmail="true"
passwordFormat="Hashed" />
</providers>
</membership>
VB code behind the fact:
Public Function Register(ByVal EncryptedName As String, ByVal EncryptedEmail As String) As String
Dim ret As String = ""
Try
Dim Provider As MembershipProvider = Membership.Providers.Item("SqlProvider")
Dim createStatus As MembershipCreateStatus
Dim newUser As MembershipUser = Provider.CreateUser(EncryptedName, Membership.GeneratePassword(8, 1), EncryptedEmail, "Your favorite color?", "RED", True, Guid.NewGuid, createStatus)
Select Case createStatus
Case MembershipCreateStatus.Success
ret = "The user account was successfully created!"
Case MembershipCreateStatus.DuplicateUserName
ret = "There already exists a user with this username."
Case MembershipCreateStatus.DuplicateEmail
ret = "There already exists a user with this email address."
Case MembershipCreateStatus.InvalidEmail
ret = "The email address provided is invalid."
Case MembershipCreateStatus.InvalidAnswer
ret = "The security answer is invalid."
Case MembershipCreateStatus.InvalidPassword
ret = "The password you provided is invalid. It must be seven characters long and have at least one non-alphanumeric character."
Case Else
ret = "There was an unknown error; the user account was NOT created."
End Select
Catch ex As Exception
Return "Server Error."
End Try
Return ret
End Function
For reference sake this is a webservice that we're using to allow users to register from our website and from desktop software. I don't know if it is the desktop software that is causing this problem. Right now I'm getting an exception on the create new user line. The exception says 'Login failed for 'DOMAIN/user' where DOMAIN is my work domain and user is my work login for my PC.
I've been looking around and found I needed to explicitly tell which provider to use (the provider checks out fine). I found a lot of samples where people simply used Membership.CreateUser but I found it wasn't loading the correct login.
I also tried playing with the authentication tag in the web.config.
The simple idea is to programmatically register new users through a webservice so it can be used with website and multiple in house desktop software applications.
Thanks for any help.