[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 669
  • Last Modified:

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


            <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" />

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



  • 2
1 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
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 :-)

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now