If You want in Your application to handle access denied exceptions in the same way as SharePoint, then just use the SPUtility.HandleAccessDenied method.

In most common scenarios it will return a 401 exception and ask user to authenticate.

To use it just call method like this:


if(userIsAdmin == false)


SPUtility.HandleAccessDenied(new AccessDeniedException("ACCESS DENIED"));