将权限分配给我在C#中创建的网站 [英] Assign permission to website i created in c#
本文介绍了将权限分配给我在C#中创建的网站的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您对此不确定,但是我想实现的目标是
Hi am not sure about this but what I am trying to achieve is
将权限分配给我使用web.add从根网站创建的网站
现在,对于创建的子网站,我想破坏继承,摆脱对它从根继承的网站的权限,最后添加具有贡献功能的特定sp组.
我该怎么做...真的很困扰.
assigning permission to a website that i created from root site using web.add
Now for the subsite created I want to break inheritance , get rid of permission to website it inherited from root and finally add a certain sp group with contribute functions.
How can i do this ... really stuck with this.
推荐答案
此处是供您参考的代码.
static void Main(string[] args)
{
using (SPSite site = new SPSite(@"http://sp:12001/"))
{
using (SPWeb parentWeb = site.RootWeb)
{
string webTitle = "CreatedByCode";
string webDesc = "A site created by a console application.";
string webName = "CreatedByCode";
string webUrl = String.Format("{0}/{1}", parentWeb.Name, webName);
uint webLcid = parentWeb.Language;
// Name value for the team site template.
string webTemplateName = "STS#0";
SPWeb newWeb = null;
// Create the new web.
try
{
newWeb = site.AllWebs.Add(webUrl, webTitle, webDesc, webLcid, webTemplateName, false, false);
}
catch (ArgumentException ex)
{
Console.WriteLine(ex.Message);
}
// Add a link to the new web on the RootWeb's topnav bar.
if (newWeb != null)
{
// Set the new web's top link bar to inherit links from its parent web.
newWeb.Navigation.UseShared = true;
newWeb.BreakRoleInheritance(false);
var groupName = "Group Name";
var groupDescription = "Group Description";
SPMember groupOwner =newWeb.EnsureUser(@"contoso\lee");
SPUser defaultUser = null;
newWeb.SiteGroups.Add(groupName, groupOwner, defaultUser, groupDescription);
var group = newWeb.SiteGroups[groupName];
var spRoleAssignment = new SPRoleAssignment(group);
var permissionName = "Contribute";
spRoleAssignment.RoleDefinitionBindings.Add(newWeb.RoleDefinitions[permissionName]);
newWeb.RoleAssignments.Add(spRoleAssignment);
newWeb.Update();
newWeb.Dispose();
}
}
}
}
一个链接供您参考.
最好的问候,
Lee
这篇关于将权限分配给我在C#中创建的网站的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文