SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Lets say I have a few users in a group called "Restricted" and I don't want them to be able to view or submit forms. Should I add some code in the Form_Loading event that checks what groups the current user is a member of? If so, how would I prevent the form from loading? So far the code I have doesn't seem to work.

SPGroupCollection grpCol = SPContext.Current.Web.CurrentUser.Groups;

                SPGroup group = grpCol["Restricted"];

                // if this doesn't throw an exception, they are not part of that group, so exit
            catch (Exception ex)
                // if exception is thrown, they don't belong to that group, so continue                                        
share|improve this question
up vote 2 down vote accepted

The standard way for SharePoint to handle this is to call:

SPUtility.HandleAccessDenied(new UnauthorizedAccessException());
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.