2012-03-26 5 views
2

ProfileBaseを使用してカスタムプロファイルクラスを作成しましたが、情報の挿入に問題があります。私はaspの登録ウィザードを使用してユーザーを作成し、CreateUserWizard1_CreatedUserメソッドでProfileに情報を追加するコードを記述しました。カスタムプロファイルはユーザー情報を複製します

ProfileUser pc = ProfileUser.GetUserProfile(UserName); 
pc.FirstName = name.Text; 
pc.LastName = lastname.Text; 
pc.Save(); 

マイProfileUserカスタムクラスがある:

namespace CancerApp 
{ 

     public class ProfileUser : ProfileBase 
     { 
      [SettingsAllowAnonymous(false)] 
      public string FirstName 
      { 
       get { return base["FirstName"] as string; } 
       set { base["FirstName"] = value; } 
      } 

      [SettingsAllowAnonymous(false)] 
      public string LastName 
      { 
       get { return base["LastName"] as string; } 
       set { base["LastName"] = value; } 
      } 

      public static ProfileUser GetUserProfile(string username) 
      { 
       return Create(username) as ProfileUser; 
      } 

      public static ProfileUser GetUserProfile() 
      { 
       return Create(Membership.GetUser().UserName) as ProfileUser; 
      } 
     } 

} 

私のWeb.config:

<profile inherits="CancerApp.ProfileUser"> 
     <providers> 
     <clear /> 
     <add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" /> 
     </providers> 
    </profile> 

問題は何ですか? pc.Save()を実行すると、異なるApplicationIDとUserIdを持つaspnet_Usersテーブルに重複した情報が作成されます。

enter image description here

任意のアイデア?

更新:私はアプリケーションを公開するときにのみ発生しますが、私はすべてが

答えて

0

今日、私はちょうど問題を解決大丈夫デバッグを開始するときに使用。彼はアプリケーションに名前を割り当てていなかったので、別のユーザーを作成していました。

プロファイル関数の名前のアプリケーションを正しく割り当てる必要があります。名前がないので、システムは自動的にアプリケーションから名前を作成し、そこに別のApplicationIdを作成する理由があります。

1

プロファイルと会員のアプリケーション名は、web.configファイルで同じでなければなりません:

<profile defaultProvider="SqlProvider" inherits="YourNamespace.AccountProfile"> 
    <providers> 
    <clear /> 
    <add name="SqlProvider" 
     type="System.Web.Profile.SqlProfileProvider" 
     connectionStringName="memConnStr" 
     **applicationName="MyApplication"/>** 
    </providers> 
</profile> 
<membership defaultProvider="SqlProvider" userIsOnlineTimeWindow="15">  
    <providers> 
    <clear /> 
    <add 
     name="SqlProvider" 
     type="System.Web.Security.SqlMembershipProvider" 
     connectionStringName="memConnStr" 
     **applicationName="MyApplication"** 
     enablePasswordRetrieval="false" 
     enablePasswordReset="true" 
     requiresQuestionAndAnswer="false" 
     requiresUniqueEmail="true" 
     minRequiredNonalphanumericCharacters="0" 
     passwordFormat="Hashed" />   
    </providers> 
</membership> 
関連する問題