Link to home
Start Free TrialLog in
Avatar of andycrellin
andycrellin

asked on

asp.net 2.0 Problems with CreateUserWizard and Login controls

Hello All,

I have (what I thought was going to be) a simple site in development. The basics are:

I have a development machine at home with VS2005
I have a hosted website with a SQL server 2000 account (I have not yet run the site on the hosted server, just my dev machine)
The SQL server database comes ready built with all of the ASP.NET 2 membership, role, and profile tables (hostinguk.net are the hosts) - so I'm pretty happy with that side of things - and I am using it to store all membership info.

I have altered my web.config to use the hosted SQL server database for all membership, role and profile data.
Using a master page, I created a "Join my website" page using the CreateUserWizard control. I added a second step in the CreateUserWizard control to get some profile information (like city and country) with the intention of adding the information to the profile after the user is created - as per many books/articles I have read. The CreateUserWizard is configured to "LoginCreatedUser" when submitted - required to allow additions to the profile(?).

This Sub (to add the profile info for the user) is on the code-behind for the "Join my Website" page:
------------------------------------------------------------------------------------------------
Protected Sub CreateUserWizard1_CreatedUser(ByVal sender As Object, ByVal e As System.EventArgs) Handles CreateUserWizard1.CreatedUser
        Profile.Title = cboTitle.SelectedValue
        Profile.FirstName = txtFirstName.Text
        Profile.LastName = txtLastName.Text
        Profile.City = txtCity.Text
        Profile.Country = cboCountry.SelectedValue
    End Sub
------------------------------------------------------------------------------------------------


The web.config file is:
------------------------------------------------------------------------------------------------
<?xml version="1.0"?>

<configuration>
      <appSettings/>
      <connectionStrings>

            <add name="PGMembers" connectionString="Data Source=sql.hostinguk.net;Initial Catalog=aaaaaaaaaa;User ID=xxxxxxxxxx;Password=xxxxxxxxxx"
   providerName="System.Data.SqlClient" />
            <add name="PGRoles" connectionString="Data Source=sql.hostinguk.net;Initial Catalog=aaaaaaaaaa;User ID=xxxxxxxxxx;Password=xxxxxxxxxx"
   providerName="System.Data.SqlClient" />
            <add name="PGProfiles" connectionString="Data Source=sql.hostinguk.net;Initial Catalog=aaaaaaaaaa;User ID=xxxxxxxxxx;Password=xxxxxxxxxx"
   providerName="System.Data.SqlClient" />
            
            <add name="aaaaaaaaaaConnectionString" connectionString="Data Source=sql.hostinguk.net;Initial Catalog=aaaaaaaaaa;User ID=xxxxxxxxxx;Password=xxxxxxxxxx"
   providerName="System.Data.SqlClient" />
            
 </connectionStrings>

      <system.web>
            <roleManager enabled="true" defaultProvider="AspNetSqlPGRoleProvider">
                  <providers>
                        <add name="AspNetSqlPGRoleProvider"
                              type="System.Web.Security.SqlRoleProvider"
                              connectionStringName="PGRoles"
                              applicationName="PG"
                        />
                  </providers>
            </roleManager>
            <membership defaultProvider="AspNetSqlPGMembershipProvider">
                  <providers>
                        <add name="AspNetSqlPGMembershipProvider"
                              type="System.Web.Security.SqlMembershipProvider"
                              connectionStringName="PGMembers"
                              minRequiredPasswordLength="3"
                              minRequiredNonalphanumericCharacters="0"
                              requiresQuestionAndAnswer="true"
                              requiresUniqueEmail="true"
                              passwordFormat="Hashed"
                        />
                  </providers>
            </membership>
            <profile defaultProvider="AspNetSqlPGProfileProvider">
                  <providers>
                        <add name="AspNetSqlPGProfileProvider"
                              connectionStringName="PGProfiles"
                              applicationName="PG"
                              type="System.Web.Profile.SqlProfileProvider"
                        />
                  </providers>
                  <properties>
                        <add name="Title"/>
                        <add name="FirstName"/>
                        <add name="LastName"/>
                        <add name="City"/>
                        <add name="Country"/>
                  </properties>
            </profile>


            <compilation debug="true" strict="false" explicit="true"/>
            <pages>
                  <namespaces>
                        <clear/>
                        <add namespace="System"/>
                        <add namespace="System.Collections"/>
                        <add namespace="System.Collections.Specialized"/>
                        <add namespace="System.Configuration"/>
                        <add namespace="System.Text"/>
                        <add namespace="System.Text.RegularExpressions"/>
                        <add namespace="System.Web"/>
                        <add namespace="System.Web.Caching"/>
                        <add namespace="System.Web.SessionState"/>
                        <add namespace="System.Web.Security"/>
                        <add namespace="System.Web.Profile"/>
                        <add namespace="System.Web.UI"/>
                        <add namespace="System.Web.UI.WebControls"/>
                        <add namespace="System.Web.UI.WebControls.WebParts"/>
                        <add namespace="System.Web.UI.HtmlControls"/>
                  </namespaces>
            </pages>

            <authentication mode="Forms">
                  <forms name=".ASPXAUTH"
                              loginUrl="login.aspx"
                              protection="All"
                              timeout="30"
                              path="\"
                              requireSSL="false"
                              slidingExpiration="true"
                              cookieless="UseDeviceProfile" />
            </authentication>

      </system.web>
</configuration>
------------------------------------------------------------------------------------------------


The problems I get are these:

1. when creating a new member, the member is created in the members table OK, but the process of writing to the profile fails with "This property cannot be set for anonymous users." on the first item. It would appear to me that the user is not being authenticated, even though the control is instructed to do so.
2. If I try to log in using a page with just the login control on it (using a sucessfully created member), no login occurs. For example, I can put a loginStatus control on the page that it is redirected to, but it continues to say "Login", making it appear to me that the user is not logged in.

I'm sure (or I hope) its something simple, but the 500 points on offer show just how far towards my wit's end I am!! If you need any further code, please ask.

Cheers,

Andy.

ASKER CERTIFIED SOLUTION
Avatar of williamcampbell
williamcampbell
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of andycrellin
andycrellin

ASKER

(Duh - can't believe I didn't try sticking in the access control... :-) - cheers!)

Tried that, but... If I remove the code to add the profile info, it will quite happily create the user and log me in. However, if I subsequently logout and then attempt to log in using those credentials again, it fails with the login failure text. Bizarre.

If I leave the code to add the profile entries in it still fails with the complaint that the user is anonymous!
However, (sorry, coding and replying at the same time) just tried moving that code into the "CreateUserWizard1_ContinueButtonClick" sub and it _seems_ to work OK. (This could be another error for Wrox to add to their list - grrr).

So - it looks like the only thing now is that the login isn't working properly.

Found it.

An empty "Login1_Authenticate" sub on the login page was preventing successful authentication.

Thanks for your help - I can sleep easier now :-)