Solved 2.0 Problems with CreateUserWizard and Login controls

Posted on 2006-03-28
Last Modified: 2012-06-21
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.



Question by:andycrellin
    LVL 12

    Accepted Solution

    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

    Author Comment

    (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.


    Author Comment

    Found it.

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

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

    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    Join & Write a Comment

    In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
    IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now