ProfileBase.Create 方法

定義

建立使用者設定檔的執行個體。

多載

Create(String)

ASP.NET 用來建立指定使用者名稱的設定檔執行個體。

Create(String, Boolean)

ASP.NET 用來建立指定使用者名稱的設定檔執行個體。 使用表示使用者為已驗證或匿名的參數。

Create(String)

ASP.NET 用來建立指定使用者名稱的設定檔執行個體。

public:
 static System::Web::Profile::ProfileBase ^ Create(System::String ^ username);
public static System.Web.Profile.ProfileBase Create (string username);
static member Create : string -> System.Web.Profile.ProfileBase
Public Shared Function Create (username As String) As ProfileBase

參數

username
String

要建立設定檔的使用者名稱。

傳回

ProfileBase,表示指定使用者的設定檔。

例外狀況

Web.config 檔案 profile 區段的 enabled 屬性為 false

目前的裝載使用權限等級低於 Medium

無法建立在 Web.config 檔案 profile 區段中指定的屬性類型。

-或-

Web.config 檔案 profile 區段中屬性 (Property) 的 allowAnonymous 屬性 (Attribute) 設定為 true,而且 <anonymousIdentification> 元素的 enabled 屬性設定為 false

-或-

Web.config 檔案 profile 區段中屬性 (Property) 的 serializeAs 屬性 (Attribute) 設定為 Binary,而且所指定 typeIsSerializable 屬性 (Property) 傳回 false

-或-

Providers 集合中找不到使用設定檔屬性 (Property) 之 provider 屬性 (Attribute) 指定的提供者名稱。

-或-

找不到指定給設定檔中某個屬性的 type

-或-

指定設定檔屬性所使用的名稱,符合在 profile 區段 inherits 屬性中所指定基底類別上的屬性名稱。

範例

下列程式碼範例會建立自訂設定檔物件的實例、設定 屬性,並將設定檔儲存至資料來源。

MyCustomProfile myProfile = (MyCustomProfile)ProfileBase.Create("username");
myProfile.ZipCode = "98052";
myProfile.Save();
Dim myProfile As MyCustomProfile = CType(ProfileBase.Create("username"), MyCustomProfile)
myProfile.ZipCode = "98052"
myProfile.Save()

備註

方法 Create 會建立並初始化新的設定檔實例,而且對於在 non-ASP.NET 環境中使用自訂設定檔物件或管理使用者設定檔的應用程式很有用。

方法的 Create 這個多載假設指定的使用者名稱是已驗證的使用者。

另請參閱

適用於

Create(String, Boolean)

ASP.NET 用來建立指定使用者名稱的設定檔執行個體。 使用表示使用者為已驗證或匿名的參數。

public:
 static System::Web::Profile::ProfileBase ^ Create(System::String ^ username, bool isAuthenticated);
public static System.Web.Profile.ProfileBase Create (string username, bool isAuthenticated);
static member Create : string * bool -> System.Web.Profile.ProfileBase
Public Shared Function Create (username As String, isAuthenticated As Boolean) As ProfileBase

參數

username
String

要建立設定檔的使用者名稱。

isAuthenticated
Boolean

true 表示使用者已驗證,false 表示使用者為匿名。

傳回

ProfileBase 物件,表示指定使用者的設定檔。

例外狀況

Web.config 檔案 profile 區段的 enabled 屬性為 false

目前的裝載使用權限等級低於 Medium

無法建立在 Web.config 檔案 profile 區段中指定的屬性類型。

-或-

Web.config 檔案 profile 區段中屬性 (Property) 的 allowAnonymous 屬性 (Attribute) 設定為 true,而且 <anonymousIdentification> 元素的 enabled 屬性設定為 false

-或-

Web.config 檔案 profile 區段中屬性 (Property) 的 serializeAs 屬性 (Attribute) 設定為 Binary,而且所指定 typeIsSerializable 屬性 (Property) 傳回 false

-或-

Providers 集合中找不到使用設定檔屬性 (Property) 之 provider 屬性 (Attribute) 指定的提供者名稱。

-或-

找不到指定給設定檔中某個屬性的 type

-或-

指定設定檔屬性所使用的名稱,符合在 profile 區段 inherits 屬性中所指定基底類別上的屬性名稱。

範例

下列程式碼範例會建立自訂設定檔物件的實例、設定 屬性,並將設定檔儲存至資料來源。

MyCustomProfile profile = (MyCustomProfile)ProfileBase.Create("username", true);
profile.ZipCode = "98052";
profile.Save();
Dim profile As MyCustomProfile = CType(ProfileBase.Create("username", True), MyCustomProfile)
profile.ZipCode = "98052"
profile.Save()

備註

方法 Create 會建立並初始化新的設定檔實例,而且對於在 non-ASP.NET 環境中使用自訂設定檔物件或管理使用者設定檔的應用程式很有用。

這個 方法的多 Create 載可用來為已驗證的使用者或匿名使用者建立設定檔。

另請參閱

適用於