SqlMembershipProvider.ApplicationName 属性

定义

获取或设置要存储和检索其成员资格信息的应用程序的名称。Gets or sets the name of the application to store and retrieve membership information for.

public:
 virtual property System::String ^ ApplicationName { System::String ^ get(); void set(System::String ^ value); };
public override string ApplicationName { get; set; }
member this.ApplicationName : string with get, set
Public Overrides Property ApplicationName As String

属性值

应用程序的名称,将存储和检索该应用程序的成员资格信息。The name of the application to store and retrieve membership information for. 默认值为当前 ApplicationPathRequest 属性值。The default is the ApplicationPath property value for the current Request.

异常

尝试将 ApplicationName 属性设置为空字符串或 nullAn attempt was made to set the ApplicationName property to an empty string or null.

尝试将 ApplicationName 属性设置为长于 256 个字符的字符串。An attempt was made to set the ApplicationName property to a string that is longer than 256 characters.

示例

下面的代码示例演示 ASP.NET 应用程序的 web.config system.web文件的节中的成员身份元素。The following code example shows the membership element in the system.web section of the Web.config file for an ASP.NET application. 它指定应用程序的SqlMembershipProvider实例,并ApplicationName将设置MyApplication为。It specifies the application's SqlMembershipProvider instance and sets the ApplicationName to MyApplication.

<membership defaultProvider="SqlProvider" userIsOnlineTimeWindow="20">  
  <providers>  
    <add name="SqlProvider"  
      type="System.Web.Security.SqlMembershipProvider"  
      connectionStringName="SqlServices"  
      enablePasswordRetrieval="true"  
      enablePasswordReset="false"  
      requiresQuestionAndAnswer="true"  
      passwordFormat="Encrypted"  
      applicationName="MyApplication" />  
  </providers>  
</membership>  

注解

ApplicationName 由用来对SqlMembershipProvider用户信息进行分组。The ApplicationName is used by the SqlMembershipProvider to group user information. 通过使用应用程序名称限定用户信息,你可以将多个应用程序的信息存储在单个数据库中,而不会在重复用户名之间发生冲突。By qualifying user information with an application name, you can store information for multiple applications in a single database without running into conflicts between duplicate user names. 另外,多个 ASP.NET 应用程序可以通过在ApplicationName属性中指定相同的值,来使用相同的用户数据库。Also, multiple ASP.NET applications can use the same user database by specifying the same value in the ApplicationName property. 可以ApplicationName通过编程方式设置该属性,也可以在applicationName具有属性的 Web 应用程序的配置文件中以声明方式设置该属性。The ApplicationName property can be set programmatically, or it can be set declaratively in the configuration file for the Web application with the applicationName attribute.

如果没有为 Web 应用程序的配置applicationName文件中的属性指定值, ApplicationPath则使用对应用程序发出的第一个请求的属性值。If a value is not specified for the applicationName attribute in the configuration file for the Web application, then the ApplicationPath property value for the first request made to the application is used.

注意

由于单个默认成员资格提供程序实例用于某个HttpApplication对象提供的所有请求,因此可以同时执行多个请求并尝试设置该ApplicationName属性值。Because a single default membership provider instance is used for all of the requests served by an HttpApplication object, you can have multiple requests executing concurrently and attempting to set the ApplicationName property value. 对于ApplicationName多个写入,属性不是线程安全的,并且ApplicationName更改属性值可能会导致应用程序的多个用户产生意外行为。The ApplicationName property is not thread safe for multiple writes, and changing the ApplicationName property value can result in unexpected behavior for multiple users of an application. 建议你避免编写代码来允许用户设置ApplicationName属性,除非你必须这样做。We recommend that you avoid writing code to allow users to set the ApplicationName property unless you must. 可能需要设置ApplicationName属性的应用程序的一个示例是管理多个应用程序的成员资格数据的管理应用程序。An example of an application where setting the ApplicationName property may be required is an administrative application that manages membership data for multiple applications. 此类应用程序应为单用户应用程序,而不是 Web 应用程序。Such an application should be a single-user application and not a Web application.

适用于

另请参阅