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_CreatedU ser(ByVal sender As Object, ByVal e As System.EventArgs) Handles CreateUserWizard1.CreatedU ser
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;I nitial Catalog=aaaaaaaaaa;User ID=xxxxxxxxxx;Password=xxx xxxxxxx"
providerName="System.Data. SqlClient" />
<add name="PGRoles" connectionString="Data Source=sql.hostinguk.net;I nitial Catalog=aaaaaaaaaa;User ID=xxxxxxxxxx;Password=xxx xxxxxxx"
providerName="System.Data. SqlClient" />
<add name="PGProfiles" connectionString="Data Source=sql.hostinguk.net;I nitial Catalog=aaaaaaaaaa;User ID=xxxxxxxxxx;Password=xxx xxxxxxx"
providerName="System.Data. SqlClient" />
<add name="aaaaaaaaaaConnection String" connectionString="Data Source=sql.hostinguk.net;I nitial Catalog=aaaaaaaaaa;User ID=xxxxxxxxxx;Password=xxx xxxxxxx"
providerName="System.Data. SqlClient" />
</connectionStrings>
<system.web>
<roleManager enabled="true" defaultProvider="AspNetSql PGRoleProv ider">
<providers>
<add name="AspNetSqlPGRoleProvi der"
type="System.Web.Security. SqlRolePro vider"
connectionStringName="PGRo les"
applicationName="PG"
/>
</providers>
</roleManager>
<membership defaultProvider="AspNetSql PGMembersh ipProvider ">
<providers>
<add name="AspNetSqlPGMembershi pProvider"
type="System.Web.Security. SqlMembers hipProvide r"
connectionStringName="PGMe mbers"
minRequiredPasswordLength= "3"
minRequiredNonalphanumeric Characters ="0"
requiresQuestionAndAnswer= "true"
requiresUniqueEmail="true"
passwordFormat="Hashed"
/>
</providers>
</membership>
<profile defaultProvider="AspNetSql PGProfileP rovider">
<providers>
<add name="AspNetSqlPGProfilePr ovider"
connectionStringName="PGPr ofiles"
applicationName="PG"
type="System.Web.Profile.S qlProfileP rovider"
/>
</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.Collecti ons"/>
<add namespace="System.Collecti ons.Specia lized"/>
<add namespace="System.Configur ation"/>
<add namespace="System.Text"/>
<add namespace="System.Text.Reg ularExpres sions"/>
<add namespace="System.Web"/>
<add namespace="System.Web.Cach ing"/>
<add namespace="System.Web.Sess ionState"/ >
<add namespace="System.Web.Secu rity"/>
<add namespace="System.Web.Prof ile"/>
<add namespace="System.Web.UI"/ >
<add namespace="System.Web.UI.W ebControls "/>
<add namespace="System.Web.UI.W ebControls .WebParts" />
<add namespace="System.Web.UI.H tmlControl s"/>
</namespaces>
</pages>
<authentication mode="Forms">
<forms name=".ASPXAUTH"
loginUrl="login.aspx"
protection="All"
timeout="30"
path="\"
requireSSL="false"
slidingExpiration="true"
cookieless="UseDeviceProfi le" />
</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.
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_CreatedU
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;I
providerName="System.Data.
<add name="PGRoles" connectionString="Data Source=sql.hostinguk.net;I
providerName="System.Data.
<add name="PGProfiles" connectionString="Data Source=sql.hostinguk.net;I
providerName="System.Data.
<add name="aaaaaaaaaaConnection
providerName="System.Data.
</connectionStrings>
<system.web>
<roleManager enabled="true" defaultProvider="AspNetSql
<providers>
<add name="AspNetSqlPGRoleProvi
type="System.Web.Security.
connectionStringName="PGRo
applicationName="PG"
/>
</providers>
</roleManager>
<membership defaultProvider="AspNetSql
<providers>
<add name="AspNetSqlPGMembershi
type="System.Web.Security.
connectionStringName="PGMe
minRequiredPasswordLength=
minRequiredNonalphanumeric
requiresQuestionAndAnswer=
requiresUniqueEmail="true"
passwordFormat="Hashed"
/>
</providers>
</membership>
<profile defaultProvider="AspNetSql
<providers>
<add name="AspNetSqlPGProfilePr
connectionStringName="PGPr
applicationName="PG"
type="System.Web.Profile.S
/>
</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.Collecti
<add namespace="System.Collecti
<add namespace="System.Configur
<add namespace="System.Text"/>
<add namespace="System.Text.Reg
<add namespace="System.Web"/>
<add namespace="System.Web.Cach
<add namespace="System.Web.Sess
<add namespace="System.Web.Secu
<add namespace="System.Web.Prof
<add namespace="System.Web.UI"/
<add namespace="System.Web.UI.W
<add namespace="System.Web.UI.W
<add namespace="System.Web.UI.H
</namespaces>
</pages>
<authentication mode="Forms">
<forms name=".ASPXAUTH"
loginUrl="login.aspx"
protection="All"
timeout="30"
path="\"
requireSSL="false"
slidingExpiration="true"
cookieless="UseDeviceProfi
</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
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
Found it.
An empty "Login1_Authenticate" sub on the login page was preventing successful authentication.
Thanks for your help - I can sleep easier now :-)
An empty "Login1_Authenticate" sub on the login page was preventing successful authentication.
Thanks for your help - I can sleep easier now :-)
ASKER
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_Continu
So - it looks like the only thing now is that the login isn't working properly.