SqlMembershipProvider::ApplicationName Property

 

Gets or sets the name of the application to store and retrieve membership information for.

Namespace:   System.Web.Security
Assembly:  System.Web (in System.Web.dll)

public:
property String^ ApplicationName {
	virtual String^ get() override;
	virtual void set(String^ value) override;
}

Property Value

Type: System::String^

The name of the application to store and retrieve membership information for. The default is the ApplicationPath property value for the current Request.

Exception Condition
ArgumentException

An attempt was made to set the ApplicationName property to an empty string or null.

ProviderException

An attempt was made to set the ApplicationName property to a string that is longer than 256 characters.

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. Also, multiple ASP.NET applications can use the same user database by specifying the same value in the ApplicationName property. 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.

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.

System_CAPS_cautionCaution

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. 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. We recommend that you avoid writing code to allow users to set the ApplicationName property unless you must. An example of an application where setting the ApplicationName property may be required is an administrative application that manages membership data for multiple applications. Such an application should be a single-user application and not a Web application.

The following code example shows the element in the system.web section of the Web.config file for an ASP.NET application. 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>

.NET Framework
Available since 2.0
Return to top
Show: