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 ( 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"?>


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

            <roleManager enabled="true" defaultProvider="AspNetSqlPGRoleProvider">
                        <add name="AspNetSqlPGRoleProvider"
            <membership defaultProvider="AspNetSqlPGMembershipProvider">
                        <add name="AspNetSqlPGMembershipProvider"
            <profile defaultProvider="AspNetSqlPGProfileProvider">
                        <add name="AspNetSqlPGProfileProvider"
                        <add name="Title"/>
                        <add name="FirstName"/>
                        <add name="LastName"/>
                        <add name="City"/>
                        <add name="Country"/>

            <compilation debug="true" strict="false" explicit="true"/>
                        <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"/>

            <authentication mode="Forms">
                  <forms name=".ASPXAUTH"
                              cookieless="UseDeviceProfile" />


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.



Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

in yourWeb.config add these under system.web

            <authentication mode="Forms">
                  <forms loginUrl="login.aspx" protection="All"/>

                  <allow users="*"/>
                  <deny users="?"/>

I assume you have a login page called login.aspx

Let me know if that helped

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
andycrellinAuthor Commented:
(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.

andycrellinAuthor Commented:
Found it.

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

Thanks for your help - I can sleep easier now :-)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.