Gets or sets a value indicating whether security is enabled.
[Visual Basic]
Public Shared Property SecurityEnabled As Boolean
[C#]
public static bool SecurityEnabled {get; set;}
[C++]
public: __property static bool get_SecurityEnabled();
public: __property static void set_SecurityEnabled(bool);
[JScript]
public static function get SecurityEnabled() : Boolean;
public static function set SecurityEnabled(Boolean); Property Value
true if security is enabled; otherwise, false.
Exceptions
Remarks
This property is used by the Code Access Security Policy Tool (Caspol.exe) -security (-s) option to turn off code-based security.
SecurityEnabled provides a way for administrators to disable code access security. When code access security is disabled, all code access demands succeed. Effectively, this grants all code FullTrust. Disabling code access security bypasses the security system so that code might perform slightly better than the equivalent security policy granting FullTrust to all code. This property does not disable role-based security; therefore, PrincipalPermission demands are not affected.
CAUTION Disabling code access security makes the system vulnerable to attacks by malicious code such as viruses and worms. Disabling code access security does not automatically block managed code from running in any way. It only causes managed code to run without restriction by the code access security system, and should only be done with the most extreme caution. Turning off security to gain extra performance should only be done when other security measures have been taken to help protect system security. Examples of other security precautions include disconnecting from public networks, physically securing computers, and so on.
A change to this property is not persisted in the registry until SavePolicy is called. New processes will not be affected by the change until it is persisted in the registry. Changing the value of this property in a running process does not necessarily change the state in the expected manner. To ensure changes have taken effect, you must call SavePolicy and start a new process.
Example
[Visual Basic, C#, C++] The following example ensures that security is enabled.
[Visual Basic]
If Not SecurityManager.SecurityEnabled Then
Throw New SecurityException(myResourceManager.GetString("Security_Required"))
End If
. . .
If Not SecurityManager.SecurityEnabled Then
Throw New SecurityException(myResourceManager.GetString("Security_Required"))
End If
[C#]
if ( !SecurityManager.SecurityEnabled ) {
throw new SecurityException(myResourceManager.GetString("Security_Required"));
}
[C++]
if ( !SecurityManager::SecurityEnabled ) {
throw new SecurityException(myResourceManager->GetString(S"Security_Required"));
}
[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button
in the upper-left corner of the page.
Requirements
Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family
.NET Framework Security:
See Also
SecurityManager Class | SecurityManager Members | System.Security Namespace