ProfileBase.Create 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
建立一個使用者設定檔的實例。
多載
| 名稱 | Description |
|---|---|
| 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 指定使用者的個人檔案。
例外狀況
enabledWeb.config 檔案中設定檔區段的屬性為 false。
目前的主機權限等級低於 Medium。
無法建立 Web.config 檔案的 設定檔 區段中指定的屬性類型。
-或-
allowAnonymousWeb.config 檔案的設定檔區塊中屬性設定trueenabled為 ,匿名識別<元素的屬性>設false為 。
-或-
serializeAsWeb.config 檔案的剖析區段中屬性設定為 Binary ,且 的屬性為 ,且 IsSerializabletype的屬性為 false 。
-或-
使用 provider 設定檔屬性指定的提供者名稱在集合中找不到 Providers 。
-或-
無法找到該剖面屬性的指定條件 type 。
-或-
範例
以下程式碼範例建立一個自訂設定檔物件的實例,設定屬性,並將設定檔儲存到資料來源。
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 方法可建立並初始化新的設定檔實例,對於使用自訂設定檔物件或管理非 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 代表指定使用者設定檔的物件。
例外狀況
enabledWeb.config 檔案中設定檔區段的屬性為 false。
目前的主機權限等級低於 Medium。
無法建立 Web.config 檔案的 設定檔 區段中指定的屬性類型。
-或-
allowAnonymousWeb.config 檔案的設定檔區塊中屬性設定trueenabled為 ,匿名識別<元素的屬性>設false為 。
-或-
serializeAsWeb.config 檔案的剖析區段中屬性設定為 Binary ,且 的屬性為 ,且 IsSerializabletype的屬性為 false 。
-或-
使用 provider 設定檔屬性指定的提供者名稱在集合中找不到 Providers 。
-或-
無法找到該剖面屬性的指定條件 type 。
-或-
範例
以下程式碼範例建立一個自訂設定檔物件的實例,設定屬性,並將設定檔儲存到資料來源。
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 方法可建立並初始化新的設定檔實例,對於使用自訂設定檔物件或管理非 ASP.NET 環境使用者設定檔的應用程式非常有用。
這種方法的 Create 過載可以用來建立已認證使用者或匿名使用者的個人檔案。