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

表示指定用户的配置文件的 ProfileBase

例外

Web.config 文件的配置文件节中的 enabled 特性为 false

当前承载权限级别低于 Medium

未能创建在 Web.config 文件的配置文件节中指定的属性类型。

  • 或 -

将 Web.config 文件的配置文件节中某个属性的 allowAnonymous 特性设置为 true,并将 <anonymousIdentification> 元素的 enabled 特性设置为 false

  • 或 -

将 Web.config 文件配置文件节中某个属性的 serializeAs 特性设置为 Binary,指定的 typeIsSerializable 属性将返回 false

  • 或 -

未能在 Providers 集合中找到使用配置文件属性的 provider 特性指定的提供程序名称。

  • 或 -

未能找到为配置文件属性指定的 type

  • 或 -

使用与基类中的属性名称匹配的名称指定配置文件属性,基类在配置文件节的 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创建和初始化新的配置文件实例,对于使用自定义配置文件对象或管理非 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

表示指定用户的配置文件的 ProfileBase 对象。

例外

Web.config 文件的配置文件节中的 enabled 特性为 false

当前承载权限级别低于 Medium

未能创建在 Web.config 文件的配置文件节中指定的属性类型。

  • 或 -

将 Web.config 文件的配置文件节中某个属性的 allowAnonymous 特性设置为 true,并将 <anonymousIdentification> 元素的 enabled 特性设置为 false

  • 或 -

将 Web.config 文件配置文件节中某个属性的 serializeAs 特性设置为 Binary,指定的 typeIsSerializable 属性将返回 false

  • 或 -

未能在 Providers 集合中找到使用配置文件属性的 provider 特性指定的提供程序名称。

  • 或 -

未能找到为配置文件属性指定的 type

  • 或 -

使用与基类中的属性名称匹配的名称指定配置文件属性,基类在配置文件节的 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创建和初始化新的配置文件实例,对于使用自定义配置文件对象或管理非 ASP.NET 环境中的用户配置文件的应用程序非常有用。

此方法的 Create 重载可用于为经过身份验证的用户或匿名用户创建配置文件。

另请参阅

适用于