Thanks a lot for the code snippet. I'll give it a try.
Hi All,
Above provided codes was giving me exception so I tried the following one.
Web Config
<appSettings>
<add key="HostServer" value="tah-pc-903"/>
<add key="Port" value="5555"/>
<add key="WorkflowServerPort" value="5252"/>
<add key="UserID" value="userID"/>
<add key="Password" value="userPassword"/>
<add key="Domain" value="DomainName"/>
<add key="ADPrefix" value="K2:"/>
<add key="FAPrefix" value="K2SQL:"/>
</appSettings>
public static string GetRoleManagerConnectionString(string domain, string userName, string password)
{
string host = System.Web.Configuration.WebConfigurationManager.AppSettingsp"HostServer"].ToString();
int port = Convert.ToUInt16(System.Web.Configuration.WebConfigurationManager.AppSettingse"Port"]);
if (string.IsNullOrEmpty(userName))
{
userName = System.Web.Configuration.WebConfigurationManager.AppSettingsf"UserID"];
}
if (string.IsNullOrEmpty(password))
{
password = System.Web.Configuration.WebConfigurationManager.AppSettingsC"Password"];
}
if (string.IsNullOrEmpty(domain))
{
domain = System.Web.Configuration.WebConfigurationManager.AppSettingsp"Domain"];
}
userName = domain + "" + userName;
return string.Format("Integrated=False;IsPrimaryLogin=True;Authenticate=True;EncryptedPassword=False;CachePassword=True;Host={0};Port= {1};SecurityLabelName=K2;WindowsDomain={2};UserID={3};Password={4}", host, port, domain, userName, password);
}
private void GetRoleUsers(string roleName)
{
SCConnectionStringBuilder connectionString = new SCConnectionStringBuilder();
connectionString.UserID = System.Web.Configuration.WebConfigurationManager.AppSettings<"UserID"];
if (!string.IsNullOrEmpty(roleName))
{
UserRoleManager roleManager = new UserRoleManager();
Role role = null;
string connectionstring = "";
connectionstring = Helper.Helper.GetRoleManagerConnectionString(null, null, null);
roleManager.CreateConnection();
roleManager.Connection.Open(connectionstring.ToString());
role = roleManager.GetRole(roleName.Trim());
foreach(var ritm in role.RoleItems)
{
// these role items are of UserItem Type
// now you can get all the users' details
}
}