views:

26

answers:

1

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.

A: 

The membership provider is configured with a reference to a connection string. Have you confirmed it is a valid connection string? It sounds like your using the default one which will try to connect with integrated authentication. Also, the user being your login for your PC tells me either you're running from debug or IIS's application pool has an explicitly set identity.

That probably won't solve your problem, but, I wanted to offer what I could as I've had similar frustration in the past.

Gabriel
I am running it in debug and I'm pretty sure my connection string is correct (just didn't want to put it here and show password and what not). We have a functioning webservice in place right now that doesn't register users and we're planning on replacing it. I wasn't going to put this live until I got it to work. I'll play around with what you suggested though.
Fox
You were right, my fault for not paying enough attention here. It was referencing the wrong connection string.
Fox