When creating a custom script inside AuthenticationSourcesCpScripting, the script name must be unique and updated in the ExecuteCustom switch statement. In the example above, "mycustomscript" is the identifier, but you should change this to match the name of your own script.
There can only be one reference of ExecuteCustom within the AuthenticationSourcesCpScripting partial class. You cannot have multiple files each defining their own ExecuteCustom with different cases. If you need to support multiple custom scripts, they must be combined into the same switch statement inside a single ExecuteCustom implementation.
The NameValueCollection parameter allows you to call any script by passing the appropriate key/value pairs. In this example, we call the built-in ActiveDirectoryProperty script and pass adProp = proxyAddresses to retrieve the value of the proxyAddresses property from Active Directory.
Example: this.ActiveDirectoryProperty(new NameValueCollection { { "key", "ActiveDirectoryProperty" }, { "adProp", "proxyAddresses" } })
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Data;
using System.IO;
using System.Web;
namespace Centralpoint.WebSite.Modules
{
public partial class AuthenticationSourcesCpScripting
{
partial void ExecuteCustom(string key, NameValueCollection collection, ref string result, ref bool found)
{
switch (key)
{
case "mycustomscript":
result = this.myCustomScript(collection);
break;
default:
return;
}
found = true;
}
public string myCustomScript(NameValueCollection collection)
{
HttpContext.Current.Trace.Warn("myCustomScript", "-------START myCustomScript--------");
string proxyAddresses = this.ActiveDirectoryProperty(new NameValueCollection { { "key", "ActiveDirectoryProperty" }, { "adProp", "proxyAddresses" } });
HttpContext.Current.Trace.Warn("proxyAddresses", $"{proxyAddresses}");
HttpContext.Current.Trace.Warn("myCustomScript", "-------END myCustomScript--------");
return "";
}
}
}
Keywords: ActiveDirectoryProperty script, Active Directory