Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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;

            try
            {
                SPGroup group = grpCol["Restricted"];

                // if this doesn't throw an exception, they are not part of that group, so exit
                return;
            }
            catch (Exception ex)
            {
                // if exception is thrown, they don't belong to that group, so continue                                        
            }
share|improve this question
add comment

1 Answer

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
add comment

Your Answer

 
discard

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.