ProfileBase.Create 方法
定义
创建用户配置文件的实例。Creates an instance of a user profile.
重载
| Create(String) |
ASP.NET 使用它为指定的用户名创建配置文件的一个实例。Used by ASP.NET to create an instance of a profile for the specified user name. |
| Create(String, Boolean) |
ASP.NET 使用它为指定的用户名创建配置文件的一个实例。Used by ASP.NET to create an instance of a profile for the specified user name. 带有一个参数,用来指示用户是经过身份验证的用户还是匿名用户。Takes a parameter indicating whether the user is authenticated or anonymous. |
Create(String)
ASP.NET 使用它为指定的用户名创建配置文件的一个实例。Used by ASP.NET to create an instance of a profile for the specified user name.
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
要为其创建配置文件的用户的名称。The name of the user to create a profile for.
返回
表示指定用户的配置文件的 ProfileBase。An ProfileBase that represents the profile for the specified user.
例外
Web.config 文件的配置文件节中的 enabled 特性为 false。The enabled attribute of the profile section of the Web.config file is false.
未能创建在 Web.config 文件的配置文件节中指定的属性类型。A property type specified in the profile section of the Web.config file could not be created.
- 或 --or-
将 Web.config 文件的配置文件节中某个属性的 allowAnonymous 特性设置为 true,并将 <anonymousIdentification> 元素的 enabled 特性设置为 false。The allowAnonymous attribute for a property in the profile section of the Web.config file is set to true and the enabled attribute of the <anonymousIdentification> element is set to false.
- 或 --or-
将 Web.config 文件配置文件节中某个属性的 serializeAs 特性设置为 Binary,指定的 type 的 IsSerializable 属性将返回 false。The serializeAs attribute for a property in the profile section of the Web.config file is set to Binary and the IsSerializable property of the specified type returns false.
- 或 --or-
未能在 Providers 集合中找到使用配置文件属性的 provider 特性指定的提供程序名称。The name of a provider specified using the provider attribute of a profile property could not be found in the Providers collection.
- 或 --or-
未能找到为配置文件属性指定的 type。The type specified for a profile property could not be found.
- 或 --or-
使用与基类中的属性名称匹配的名称指定配置文件属性,基类在配置文件节的 inherits 特性中指定。A profile property was specified with a name that matches a property name on the base class specified in the inherits attribute of the profile section.
示例
下面的代码示例创建自定义配置文件对象的实例、设置属性,并将配置文件保存到数据源。The following code example creates an instance of a custom profile object, sets a property, and saves the profile to the data source.
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 环境中管理用户配置文件的应用程序。The Create method creates and initializes a new profile instance and is useful for applications that use a custom profile object or manage user profiles in a non-ASP.NET environment.
此方法的重载 Create 假定指定的用户名是经过身份验证的用户。This overload of the Create method assumes that the specified user name is an authenticated user.
适用于
Create(String, Boolean)
ASP.NET 使用它为指定的用户名创建配置文件的一个实例。Used by ASP.NET to create an instance of a profile for the specified user name. 带有一个参数,用来指示用户是经过身份验证的用户还是匿名用户。Takes a parameter indicating whether the user is authenticated or anonymous.
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
要为其创建配置文件的用户的名称。The name of the user to create a profile for.
- isAuthenticated
- Boolean
true 指示用户是经过身份验证的用户;false 指示用户是匿名用户。true to indicate the user is authenticated; false to indicate the user is anonymous.
返回
表示指定用户的配置文件的 ProfileBase 对象。A ProfileBase object that represents the profile for the specified user.
例外
Web.config 文件的配置文件节中的 enabled 特性为 false。The enabled attribute of the profile section of the Web.config file is false.
未能创建在 Web.config 文件的配置文件节中指定的属性类型。A property type specified in the profile section of the Web.config file could not be created.
- 或 --or-
将 Web.config 文件的配置文件节中某个属性的 allowAnonymous 特性设置为 true,并将 <anonymousIdentification> 元素的 enabled 特性设置为 false。The allowAnonymous attribute for a property in the profile section of the Web.config file is set to true and the enabled attribute of the <anonymousIdentification> element is set to false.
- 或 --or-
将 Web.config 文件配置文件节中某个属性的 serializeAs 特性设置为 Binary,指定的 type 的 IsSerializable 属性将返回 false。The serializeAs attribute for a property in the profile section of the Web.config file is set to Binary and the IsSerializable property of the specified type returns false.
- 或 --or-
未能在 Providers 集合中找到使用配置文件属性的 provider 特性指定的提供程序名称。The name of a provider specified using the provider attribute of a profile property could not be found in the Providers collection.
- 或 --or-
未能找到为配置文件属性指定的 type。The type specified for a profile property could not be found.
- 或 --or-
使用与基类中的属性名称匹配的名称指定配置文件属性,基类在配置文件节的 inherits 特性中指定。A profile property was specified with a name that matches a property name on the base class specified in the inherits attribute of the profile section.
示例
下面的代码示例创建自定义配置文件对象的实例、设置属性,并将配置文件保存到数据源。The following code example creates an instance of a custom profile object, sets a property, and saves the profile to the data source.
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 环境中管理用户配置文件的应用程序。The Create method creates and initializes a new profile instance and is useful for applications that use a custom profile object or manage user profiles in a non-ASP.NET environment.
此方法的重载 Create 可用于为经过身份验证的用户或匿名用户创建配置文件。This overload of the Create method can be used to create a profile for an authenticated user or an anonymous user.