
258
CHAPTER 9 Building a Site ProviSioning SyStem
Your form can keep a local variable referencing the list item being created or edited, as well as a
reference to an
SPSite object created under elevated privileges. To continue, declare these variables
in your class file:
1. In Solution Explorer, expand the SiteRequests.aspx node, and double-click the
SiteRequests.aspx.cs code-behind file.
2. Add member variables to the page class that can store the SPListItem for the item added or
edited and the
SPSite utilized during page execution:
protected SPListItem item;
protected SPSite elevatedSite;
Creating Form Helper Functions
Because you will be checking to see if a user is eligible to request a certain type of site, you’ll also need
to determine if the user belongs to a given Active Directory group. Add this function to your page:
private bool IsUserInGroup(string userName, string groupName)
{
PrincipalContext pc = new PrincipalContext(ContextType.Domain,
Environment.UserDomainName);
PrincipalSearchResult<Principal> searchResults;
UserPrincipal user;
user = UserPrincipal.FindByIdentity(pc, userName);
searchResults = user.GetGroups(pc);
foreach (Principal grp in searchResults)
{
string name = grp.Context.Name + “\\“ + grp.Name;
if (groupName.ToUpper() == name.ToUpper())
{
return true;
}
}
return false;
}
Next, add a helper function called IsRequestorEligible() to determine if the cu ...