简体   繁体   English

Sharepoint 2010-部署时添加组

[英]Sharepoint 2010 - Add group on deploy

in order to provide webparts and custom webtemplates for a site-collection, I need to create custom groups. 为了为网站集提供Webpart和自定义Web模板,我需要创建自定义组。 I do that in the following way: 我通过以下方式做到这一点:

     using (SPSite site = properties.Feature.Parent as SPSite)
        {
            if (site != null)
                using (SPWeb rootWeb = site.RootWeb)
                {

                    try
                    {
                        rootWeb.AllowUnsafeUpdates = true;
                        rootWeb.SiteGroups.Add("Admins", site.Owner, site.Owner, "Admins");

                        try
                        {
                            SPGroup sp_grpAdmins = rootWeb.SiteGroups["Admins"];
                            SPRoleDefinition sp_rldAdmins = 
                            rootWeb.RoleDefinitions.GetByType(SPRoleType.Administrator);
                            sp_rldAdmins.Name = "Admin rights";
                            sp_rldAdmins.Description = "all";
                            rootWeb.RoleDefinitions.Add(sp_rldAdmins);
                            SPRoleAssignment sp_rlaAdmins = new SPRoleAssignment(sp_grpAdmins);
                            sp_rlaAdmins.RoleDefinitionBindings.Add(
                            rootWeb.RoleDefinitions["Admin rights"]);
                            rootWeb.RoleAssignments.Add(sp_rlaAdmins);
                            sp_grpAdmins.Update();
                            rootWeb.Update();
                        }
                        catch (ArgumentException argex)
                        {

                        }
        }
    }

If I add this code in a webpart (for debugging samples - can't get the event receiver to debug), the group gets created. 如果我将此代码添加到Webpart中(用于调试示例-无法使事件接收器进行调试),则会创建该组。 Do you know how to either debug the feature event receiver or if there are limitations, that cannot be done in the feature event receiver? 您是否知道如何调试功能事件接收器,或者是否存在功能事件接收器无法完成的限制? Thank you very much. 非常感谢你。

you can debug event receiver by attaching Visual Studio to w3wp.exe . 您可以通过将Visual Studio附加到w3wp.exe来调试事件接收器。 Note that you should activate your feature manually cause if automatic this will be activated before your process has loaded all DLLs. 请注意,您应该手动激活功能,因为如果自动激活,则会在您的进程加载所有DLL之前将其激活。

What I usually do is to install site. 我通常要做的是安装站点。 Deploy package. 部署程序包。

In visual studio press Ctr+Alt+P (Menu->Debug->Attache to process). 在Visual Studio中,按Ctr + Alt + P(菜单->调试->附加以进行处理)。 This will open all processes running on your machine. 这将打开计算机上运行的所有进程。 If no w3wp.exe process present make sure to check "Show processes from all users" and "Show processes in all sessions". 如果不存在w3wp.exe进程,请确保选中“显示所有用户的进程”和“显示所有会话中的进程”。 Select in the list all w3wp.exe process and click attach. 在列表中选择所有w3wp.exe进程,然后单击附加。 You'll be asked about warning security - just click OK (several times if needed). 系统将询问您有关警告安全性的信息-只需单击“确定”(如果需要,可以多次单击)。

Once attached, activate feature with event receiver manually in the "Site collection fetures". 连接后,在“站点收集功能”中手动激活带有事件接收器的功能。 If everything goes well -> this will stop in it and you can continue your debug. 如果一切顺利->这将停止,您可以继续调试。

If in case it was not stopped in the event receiver I suggest you to recompile the project. 如果万一它没有在事件接收器中停止,我建议您重新编译该项目。 Package it again and redeploy. 再次打包并重新部署。 After do IIS reset - this will reset DLLs from the GAC. IIS重置后-这将从GAC重置DLL。

Note that Visual studio project should be in DEBUG mode... 请注意,Visual Studio项目应处于DEBUG模式。

If you have any question... 如果你有任何问题...

Hope it helps, 希望能帮助到你,

Andrew 安德鲁

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM