Export (0) Print
Expand All

Roles::ApplicationName Property

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

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

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

Property Value

Type: System::String
The name of the application to store and retrieve role information for.

The ApplicationName property is used by the Roles class to associate users and roles with different applications. This enables multiple applications to use the same data source to store user and role information without running into conflicts between duplicate user names or duplicate role names. Multiple ASP.NET applications can use the same data source by specifying the same value in the ApplicationName property. You can set the ApplicationName property programmatically, or you can set it declaratively in the configuration file for the Web application by using the applicationName attribute.

If your Web application is using the SqlRoleProvider class and a value is not specified for the applicationName attribute in the configuration file, the HttpRequest::ApplicationPath property value for the current HttpContext::Request property is used.

Caution noteCaution

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

The following example shows the roleManager element in the system.web section of the Web.config file for an ASP.NET application. It specifies that the application uses a SqlRoleProvider instance and sets the applicationName attribute to MyApplication.

<roleManager defaultProvider="SqlProvider" 
  enabled="true"
  cacheRolesInCookie="true"
  cookieName=".ASPROLES"
  cookieTimeout="30"
  cookiePath="/"
  cookieRequireSSL="false"
  cookieSlidingExpiration="true"
  cookieProtection="All" >
  <providers>
    <add
      name="SqlProvider"
      type="System.Web.Security.SqlRoleProvider"
      connectionStringName="SqlServices"
      applicationName="MyApplication" />
  </providers>
</roleManager>

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft