Showing posts with label Permissions. Show all posts
Showing posts with label Permissions. Show all posts

Monday, March 9, 2009

How to check the authorization to load a page ?

I achived to check the authrization of user follwoing way.

public static bool IsUserExistsInGroup(string aGroupName, SPWeb aWeb, string aUserName)
{
SPGroup userGroup;
SPUser user;
bool userExists = false;
try
{
userGroup = aWeb.Site.RootWeb.SiteGroups[aGroupName];
try
{
user = userGroup.Users[aUserName];

if (user != null)
{
userExists = true;
}
}
catch
{

}
}
catch (Exception ex)
{
throw ex;
}
return userExists;
}

Friday, August 29, 2008

Break the permissions inheritance of a site

This code allows you to break the permissions inheritance of a site

string siteGroupNamePublisher = "SampleReadOnly";
string desc = "A group to manage read only user for root site";
siteCol = (SPSite)properties.Feature.Parent;
site = siteCol.RootWeb;
try {
SPSecurity.RunWithElevatedPrivileges(delegate() {
//Start--Creating SampleGroup which has read permissions n Break Inheritense
logFile.WriteInfo(CLASS, "FeatureActivated", "Creating SampleGroup which has read permissions n Break Inheritence", debugInfo);
SPGroup secGroup1;
SPRoleAssignment roleAssignment1;
SPRoleDefinition roleDefinition1;
site.SiteGroups.Add(siteGroupNamePublisher, site.CurrentUser, site.CurrentUser, desc);
secGroup1 = site.SiteGroups[siteGroupNamePublisher];
roleAssignment1 = new SPRoleAssignment(secGroup1);
roleDefinition1 = site.RoleDefinitions["Read"]; roleAssignment1.RoleDefinitionBindings.Add(roleDefinition1); site.RoleAssignments.Add(roleAssignment1);
//End--Creating SampleGroup which has read permissions n Break Inheritense
});