Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net Security (http://www.velocityreviews.com/forums/f62-asp-net-security.html)
-   -   ProfileCommon.Create creates user with wrong apllicationID (provider) (http://www.velocityreviews.com/forums/t769997-profilecommon-create-creates-user-with-wrong-apllicationid-provider.html)

news.microsoft.com 12-11-2008 09:17 PM

ProfileCommon.Create creates user with wrong apllicationID (provider)
 
I have this code that should save a user with a specific applicationID:

protected void btnSaveUser_Click(object sender, EventArgs e)
{
string username = this.txtUsername.Text;
string firstname = this.txtFirstname.Text;
string lastname = this.txtLastname.Text;
string password = this.txtPassword.Text;
string email = this.txtEmail.Text;
int siteId = int.Parse(this.txtSiteId.Text);

MembershipCreateStatus status;
MembershipProvider mp = Membership.Providers[siteId.ToString()];
MembershipUser user = mp.CreateUser(username, password, email, null,
null, true, null, out status);

ProfileCommon p = (ProfileCommon)ProfileCommon.Create(user.UserName,
true);
p.FirstName = firstname;
p.LastName = lastname;
p.Save();

if (status == MembershipCreateStatus.Success)
{
// party!
}
}

In web.config I have 2 different applications (providers) like this:

<membership defaultProvider="1" userIsOnlineTimeWindow="15">
<providers>
<clear/>
<add name="1" applicationName="1"
type="System.Web.Security.SqlMembershipProvider, System.Web,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
connectionStringName="ConnString" enablePasswordRetrieval="false"
enablePasswordReset="true" requiresQuestionAndAnswer="false"
requiresUniqueEmail="false" passwordFormat="Hashed"
maxInvalidPasswordAttempts="5" passwordAttemptWindow="10"
passwordStrengthRegularExpression="" minRequiredPasswordLength="7"
minRequiredNonalphanumericCharacters="1"/>
<add name="2" applicationName="2"
type="System.Web.Security.SqlMembershipProvider, System.Web,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
connectionStringName="ConnString" enablePasswordRetrieval="false"
enablePasswordReset="true" requiresQuestionAndAnswer="false"
requiresUniqueEmail="false" passwordFormat="Hashed"
maxInvalidPasswordAttempts="5" passwordAttemptWindow="10"
passwordStrengthRegularExpression="" minRequiredPasswordLength="7"
minRequiredNonalphanumericCharacters="1"/>
</providers>
</membership>
<roleManager defaultProvider="1" enabled="false" cacheRolesInCookie="false"
cookieName=".ASPXROLES" cookieTimeout="30" cookiePath="/"
cookieRequireSSL="false" cookieSlidingExpiration="true"
cookieProtection="All" createPersistentCookie="false" maxCachedResults="25">
<providers>
<clear />
<add name="1" applicationName="1" connectionStringName="ConnString"
type="System.Web.Security.SqlRoleProvider, System.Web, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<add name="2" applicationName="2" connectionStringName="ConnString"
type="System.Web.Security.SqlRoleProvider, System.Web, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</providers>
</roleManager>
<profile enabled="true" defaultProvider="1">
<providers>
<clear/>
<add name="1" applicationName="1"
type="Microsoft.Samples.SqlStoredProcedureProfileP rovider"
connectionStringName="ConnString" setProcedure="setCustomProfileData"
readProcedure="getCustomProfileData" />
<add name="2" applicationName="2"
type="Microsoft.Samples.SqlStoredProcedureProfileP rovider"
connectionStringName="ConnString" setProcedure="setCustomProfileData"
readProcedure="getCustomProfileData" />
</providers>
<properties>
<add name="FirstName" defaultValue="[null]"
customProviderData="FirstName;nvarchar;50"/>
<add name="LastName" defaultValue="[null]"
customProviderData="LastName;nvarchar;50"/>
<add name="Age" type="int" customProviderData="Age;int;1"/>
</properties>
</profile>


If siteID=2 (this.txtSiteId.Text) then the users shall have applicationID=2.
It works when running mp.CreateUser();

But, when running ProfileCommon.Create() the default applicationID from
web.config is used (1), and a new user is created in the aspnet_users tabell
with applicationID 1. The profiledata is then related to this user that
should never been created, not the correct user with applicationID=2.

How can I programmatically set the correct provider (applicationID) when
saving profiledata (ProfileCommon.Create())?

Thanks for all tips!!!




All times are GMT. The time now is 08:53 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.