1

Is there any way to check the source of access denied. Sometimes users have access to the page, but do not have access to something on the page, or some code that requires access. For instance, a WP is trying to query a list that the current user does not have access to.

Is there way to find out this kind of information. I looked into SP Logs but found nothing useful. I know my Contribute user has access to the site and the page. However, a WP on the page is causing the "access denied" message.

I can try to remove each WP using ?contents=1, but I was wondering is there is a better option, that just tells you the source.

Update: My webpart is throwing access denied on contribute and read-only users. I debugged the code and none of the breakpoints get hit, not even the ones on Page_Load. I checked all the references, and the user has access to all of them. When I remove my wp, the page works fine, no access denied.

1
  • Removing WPs using ?contents=1 is not an option in my case. We cannot delete those webparts, because there are about 10 WPs in the page, and each WP has specific configurations. Removing webparts 1 by 1 to check which WP is throwing the error and adding them back is very time-consuming.
    – harsimranb
    Mar 18, 2013 at 17:30

2 Answers 2

1

Check out SPSecurity.CatchAccessDeniedException.

By default SharePoint handles access denied exceptions itself. If you set that property to false then your code can handle them.

5
  • :( Tried it but didn't make a difference. As I said, it seems the code does not even run.
    – harsimranb
    Mar 21, 2013 at 20:25
  • Have you isolated at least one offending web part?
    – Chloraphil
    Mar 21, 2013 at 20:41
  • yes...i know which WP is causing it. I've added it to a blank page and only that page is giving access denied. All other pages that don't have that web part work fine.
    – harsimranb
    Mar 21, 2013 at 20:47
  • OK, so even after setting SPSecurity.CatchAccessDeniedException to false, and putting your code inside of a try/catch block, it's still not catching it?
    – Chloraphil
    Mar 21, 2013 at 20:53
  • yeh...i had try / catch long before...check my answer
    – harsimranb
    Mar 21, 2013 at 21:28
0

I tried a bunch of things, including Chloraphil's SPSecurity.CatchAccessDeniedException. Unfortunately, none worked. The breakpoints weren't getting hit anywhere on the page, not OnInit(), Page_Load(), no where.

I'm not sure what hapened, but to fix I did the following: - Create a new webpart - copy all the code/contents from the old webpart to new webpart. - It worked!

This is indeed pain, because now I have to go to all the pages and re-add/re-configure the webpart.

I've had something like this a few times before, where recreating the webpart fixed unknown/weird issues.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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