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

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.

share|improve this question
    
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. –  Pathachiever11 Mar 18 '13 at 17:30
add comment

2 Answers 2

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.

share|improve this answer
    
Thanks a ton! I will give it a try! –  Pathachiever11 Mar 21 '13 at 18:08
    
:( Tried it but didn't make a difference. As I said, it seems the code does not even run. –  Pathachiever11 Mar 21 '13 at 20:25
    
Have you isolated at least one offending web part? –  Chloraphil Mar 21 '13 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. –  Pathachiever11 Mar 21 '13 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 '13 at 20:53
show 1 more comment
up vote 0 down vote accepted

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.

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.