Cannot detect SharePoint Access denied error

I am trying to access a sharepoint list programmatically in a web part, for example.

try { masterList = web.Lists[listId]; } catch(Exception e) { RenderExceptionMessage(e.Message); } 

The RenderExceptionMessage () method is supposed to display a user-friendly error message inside the web part.

But the problem is that I cannot catch the exception. Instead, the web page is redirected to the access denied page, which displays the error message "You are currently logged in as: Domain \ User"

In addition, the message about the catch exception reads "Unable to evaluate the expression because the code is optimized or the native frame is on top of the call stack."

Any idea why this behaves this way?

+7
sharepoint moss sharepoint-2007
source share
2 answers

By default, SharePoint has custom processing for access to prohibited exceptions (including redirecting to a custom page) in page / web service requests, bypassing the exception handling in your code.

To disable this custom processing, set SPSecurity.CatchAccessDeniedException to false.

+9
source share

Perhaps another way to handle this is to add security programming, such as verification, to make sure the user has access to SPWeb and / or SPList. At the top of my head, I think SPWeb.EnsureUser might help. SPList.CheckPermissions or SPList.DoesUserHavePermissions can also help.

+1
source share

All Articles