Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

SqlRoleProvider.ApplicationName Property

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

Namespace: System.Web.Security
Assembly: System.Web (in system.web.dll)
public override string ApplicationName { get; set; }
/** @property */
public String get_ApplicationName ()

/** @property */
public void set_ApplicationName (String value)

public override function get ApplicationName () : String

public override function set ApplicationName (value : String)

Not applicable.

Property Value

The name of the application for which to store and retrieve role information. The default is the System.Web.HttpRequest.ApplicationPath property value for the current System.Web.HttpContext.Request.
Exception typeCondition

HttpException

An attempt was made to set the ApplicationName property by a caller that does not have High ASP.NET hosting permission.

System.Configuration.Provider.ProviderException

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

The ApplicationName is used by the SqlRoleProvider to associate users and roles with different applications. This enables multiple applications to use the same database to store user and role information without running into conflicts between duplicate user names or role names. Multiple ASP.NET applications can use the same 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 using the applicationName attribute.

If a value is not specified for the applicationName attribute in the configuration file for the Web application, then the System.Web.HttpRequest.ApplicationPath property value for the current System.Web.HttpContext.Request object 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. It is recommended that you avoid writing code that allows 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 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 the application's SqlRoleProvider instance and sets the ApplicationName property 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>

Windows 98, Windows Server 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.