Please ensure Javascript is enabled for purposes of website accessibility
Powered by Zoomin Software. For more details please contactZoomin

AF SDK Reference

AFSecurity.SetAccessControl Method

  • Last UpdatedNov 18, 2025
  • 5 minute read
AFSecurity.SetAccessControl Method

Note: This API is now obsolete.

Sets the access control security descriptor for the associated object.

Namespace:  OSIsoft.AF
Assembly:  OSIsoft.AFSDK (in OSIsoft.AFSDK.dll) Version: 3.1.1.1182

Syntax

[BrowsableAttribute(false)]
[ObsoleteAttribute("Replace with the SetSecurityString method instead.")]
public void SetAccessControl(
	string securityDescriptor,
	bool applyToChildren
)
<BrowsableAttribute(false)>
<ObsoleteAttribute("Replace with the SetSecurityString method instead.")>
Public Sub SetAccessControl ( 
	securityDescriptor As String,
	applyToChildren As Boolean
)

Dim instance As AFSecurity
Dim securityDescriptor As String
Dim applyToChildren As Boolean

instance.SetAccessControl(securityDescriptor, 
	applyToChildren)
public:
[BrowsableAttribute(false)]
[ObsoleteAttribute(L"Replace with the SetSecurityString method instead.")]
void SetAccessControl(
	String^ securityDescriptor, 
	bool applyToChildren
)
[<BrowsableAttribute(false)>]
[<ObsoleteAttribute("Replace with the SetSecurityString method instead.")>]
member SetAccessControl : 
        securityDescriptor : string * 
        applyToChildren : bool -> unit 

Parameters

securityDescriptor
Type: SystemString
The new access control security descriptor for the associated object.
applyToChildren
Type: SystemBoolean

This parameter only has an effect if the associated object is an AFElement or AFEventFrame that has been added to a collection and saved to the server. For all other objects or if this parameter is , then the new access permissions are only applied to the associated object.

If and the associated object is an AFElement or AFEventFrame that has been added to a collection, then the access permissions for any parent or child objects might also change. The behavior depends on the reference type:

  • For weak reference types, access permissions are never inherited. So, if you change the access permissions for the parent object, the permissions for the child object are not affected. Similarly, if you change the access permissions for the child object, the permissions for the parent object are not affected.
  • For parent-child reference types, child permissions change when you change the permissions on the primary parent permissions. Parent permissions do not change when you change child permissions. Child elements that have a parent-child reference to the parent element, but are owned by a different element, are not in the primary path and will not have their permissions modified.
If the AFElement or AFEventFrame is a new object that has not been saved to the server, then it will be automatically saved so that the server can apply the security changes to the children.

Note Notes to Callers
For composition reference types, access permissions for child and parent are always the same, therefore the value of this parameter is ignored. So, if you change the access permissions for the child, the parent access permissions are automatically changed to match the child permissions. Similarly, if you change the access permissions for the parent, the child access permissions are automatically changed to match the parent permissions. These changes cascade down (and up) through the hierarchy.

Exceptions

ExceptionCondition
ArgumentNullException This exception is thrown if the securityDescriptor is or an empty string.
NotSupportedException This exception is thrown if attempting to set security on an AFSecurityIdentity or AFSecurityMapping object.

Remarks

This method uses the Security Descriptor String Format as defined by Microsoft for setting the security access rules for the associated object. See the Security Descriptor String Format section of the Security Formats topic for a description of the format of the securityDescriptor string parameter.
Important note Important
Setting security on AFSecurityIdentity or AFSecurityMapping is not supported. You must set the security on the corresponding PISystem collection for these object types.
Note Notes to Callers
For PI AF Server 2.7 or later you can call the SetSecurityString(String, Boolean) method to set the security access control with the new security identities (see AFSecurityIdentity) which is supported by newer servers. You can use the PISystem.Supports method to check if the server supports SecurityIdentity.

Examples

// Get the Database
PISystems myPISystems = new PISystems();
PISystem myPISystem = myPISystems.DefaultPISystem;
AFDatabase myDB = myPISystem.Databases.DefaultDatabase;

// Create the Element
AFElement myElement = myDB.Elements.Add("MyElement#1");
myElement.CheckIn();

// Set Security Descriptor to Deny Write and WriteData for Everyone
AFSecurity security = myElement.Security;
string descriptor = "O:BAG:BAD:(D;;DCDT;;;WD)(A;;CCWP;;;WD)";
security.SetAccessControl(descriptor, false);

// Check Security Rights
Console.WriteLine("Element CanRead = {0}", security.CanRead);
Console.WriteLine("Element CanWrite = {0}", security.CanWrite);

// Ensure element is returned in search results for current user
AFElementSearch search = new AFElementSearch(myDB, "Search", "Name:'MyElement*");
int totalCount = search.GetTotalCount();
Console.WriteLine("Element count = {0}", totalCount);
' Get the Database
Dim myPISystems As New PISystems()
Dim myPISystem As PISystem = myPISystems.DefaultPISystem
Dim myDB As AFDatabase = myPISystem.Databases.DefaultDatabase

' Create the Element
Dim myElement As AFElement = myDB.Elements.Add("MyElement#1")
myElement.CheckIn()

' Set Security Descriptor to Deny Write and WriteData for Everyone
Dim security As AFSecurity = myElement.Security
Dim descriptor As String = "O:BAG:BAD:(D;;DCDT;;;WD)(A;;CCWP;;;WD)"
security.SetAccessControl(descriptor, False)

' Check Security Rights
Console.WriteLine("Element CanRead = {0}", security.CanRead)
Console.WriteLine("Element CanWrite = {0}", security.CanWrite)

' Ensure element is returned in search results for current user
Dim search As New AFElementSearch(myDB, "Search", "Name:'MyElement*")
Dim totalCount As Integer = search.GetTotalCount()
Console.WriteLine("Element count = {0}", totalCount)

No code example is currently available or this language may not be supported.

No code example is currently available or this language may not be supported.

Version Information

AFSDK

Supported in: 2.6, 2.5, 2.4
Obsolete (compiler warning) in 3.1.1
Obsolete (compiler warning) in 3.1.0
Obsolete (compiler warning) in 3.0.2
Obsolete (compiler warning) in 3.0.1
Obsolete (compiler warning) in 3.0.0
Obsolete (compiler warning) in 2.10.11
Obsolete (compiler warning) in 2.10.5
Obsolete (compiler warning) in 2.10.0
Obsolete (compiler warning) in 2.10
Obsolete (compiler warning) in 2.9.5
Obsolete (compiler warning) in 2.9
Obsolete (compiler warning) in 2.8.5
Obsolete (compiler warning) in 2.8
Obsolete (compiler warning) in 2.7.5
Obsolete (compiler warning) in 2.7

See Also

In This Topic
Related Links
TitleResults for “How to create a CRG?”Also Available in