Question

in order to provide webparts and custom webtemplates for a site-collection, I need to create custom groups. 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. 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.

No correct solution

OTHER TIPS

you can debug event receiver by attaching Visual Studio to w3wp.exe. Note that you should activate your feature manually cause if automatic this will be activated before your process has loaded all DLLs.

What I usually do is to install site. Deploy package.

In visual studio press Ctr+Alt+P (Menu->Debug->Attache to process). 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". Select in the list all w3wp.exe process and click attach. 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.

Note that Visual studio project should be in DEBUG mode...

If you have any question...

Hope it helps,

Andrew

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top