using Directory Services in sandboxed Solution
-
12. června 2012 9:58
hi,
I am Working on sandbox Solution i am getting error while using Directory Services,
how to use Directory Services in sand box solution.
Anwar
Všechny reakce
-
14. června 2012 6:36Moderátor
Hi Anwar,
For this issue, it would be better if you provide you code snippet to interact with directory service, and the error message you met when you testing it.
Also, here is an article about how to get user data from active directory, you can refer to it for more information about how to interact with it:
http://www.codeproject.com/Articles/6778/How-to-get-User-Data-from-the-Active-DirectoryThanks,
QiaoQiao Wei
TechNet Community Support
-
14. června 2012 6:47
What's the error? I haven't checked the exact details, but it's possible that CAS restrictions of sandboxed solutions prevent access to AD (ie, access to SQL Server databases is forbidden, so I wouldn't be surprised). Instead, it'll be easier to wrap the AD functionality in a WCF service. You can call WCF service methods without problems within the sandbox.
Check my article at http://sharepointdragons.com/2011/10/07/parallel-programming-in-sharepoint-2010-the-back-to-the-future-pattern/ for help about creating WCF services in a SharePoint environment.
Kind regards,
Margriet BruggemanLois & Clark IT Services
web site: http://www.loisandclark.eu
blog: http://www.sharepointdragons.com
- Upravený Margriet Bruggeman 14. června 2012 6:48
-
14. června 2012 7:23
hi,
This Code i written in Sand Boxed Work Flow.
public Hashtable GetUsers(SPUserCodeWorkflowContext context)
{
Hashtable results = new Hashtable();
results.Add("Except", string.Empty);
try
{
using (DirectoryEntry de = new DirectoryEntry("LDAP://XXX.com/CN=Users,dc=XX,dc=com"))
{
DirectorySearcher search = new DirectorySearcher(de);
search.Filter = "(&(objectClass=user))";
SearchResultCollection searchresults = search.FindAll();
if (searchresults.Count > 0)
{
foreach (SearchResult result in searchresults)
{
using (SPSite site = new SPSite(context.CurrentWebUrl))
{
using (SPWeb web = site.OpenWeb())
{
try
{
web.AllowUnsafeUpdates = true;
SPListItemCollection listItems = web.Lists["ManageAdmin"].Items;
SPListItem item = listItems.Add();
ResultPropertyValueCollection sAMValuesCollection = result.Properties["samAccountName"];
ResultPropertyValueCollection DisplaynameCollection = result.Properties["displayName"];
foreach (object value in sAMValuesCollection)
{
item["UserName"] = value.ToString();
}
foreach (object value in DisplaynameCollection)
{
item["DisplayName"] = value.ToString();
}
item.Update();
}
catch (Exception)
{
throw;
}
finally
{
web.AllowUnsafeUpdates = false;
}
}
}
}
}
}
}
catch (Exception ex)
{
results["Except"] = ex.ToString();
}
results["Except"]="Success";
return (results);
}
Anwar
- Upravený AnwarIndia 14. června 2012 7:35
-
14. června 2012 8:31
Anwar,
I don't see any issues with your code. Instead ask your AD administrator to give the "Administrator" privilege to your account in the AD itself to see the result.
Sometime before,I have created to WebPart to add the user to AD .Later I used to pass my login/password in AD Class.Lastly I managed to run the webpart successfully.
Murugesa Pandian.,MCTS|App.Devleopment|Configure
- Označen jako odpověď Qiao WeiMicrosoft Contingent Staff, Moderator 22. června 2012 2:27
- Zrušeno označení jako odpověď AnwarIndia 26. září 2012 9:22
-
17. listopadu 2012 13:26
Hi Anwar,
Can you write results["Except"] = ex.ToString();
this variable to history list in workflow, to see the error
or use try , catch to write the error in log file.Please post the resolution if you got it already.
Regards,
Swati -
29. prosince 2012 17:29
Hi anybody,
is it possible that this isn't possible in any way, because it's a sandbox?
Regards,
Roman
Roman Pawlig MCSD.Net MCDBA SQL Server
-
30. prosince 2012 10:05It's always possible to do it in any way, since you can always call a web service or SharePoint proxy service.
Kind regards,
Margriet BruggemanLois & Clark IT Services
web site: http://www.loisandclark.eu
blog: http://www.sharepointdragons.com