SharePoint 2010 Access Denied Web Part Error

After upgrading to SharePoint 2010 some web part pages are showing an Error Web Part Error: Access denied. You do not have permission to perform this action or access this resource.“.  For sites without anonymous access, this can be mitigated with audience targeting of the web part. However, if that does not work or you need to have the page be anonymously accessible, but also have web parts on that page that have limited permissions, then you will need a different solution. This is not the perfect solution you are looking for, I am still waiting on Microsoft for that as well, but this is a simple jQuery trick that will hide that awful error and make the page render as you would expect (MOSS 2007 functionality). Just follow the following steps:

  1. Download the latest version of jQuery from their site: http://jquery.com/ and upload it to your server.
  2. At the bottom of the page add a content editor web part and make it hidden.
  3. Add the following code:

<script src=”your-server/jquery-1.6.1.min.js”></script>
<script language=”javascript”>
$(“span:contains(‘Error’)”).hide();
$(“div:contains(‘Access denied’):not(:has(div))”).hide();
</script>

The first line is a reference to the latest version of jQuery on your server. Please remove “your-server” and replace with the correct folder (don’t use absolute references). Make sure this reference works. (It is also possible to link to a Google hosted version of this file however I always use a local copy.) The second line is the beginning tag for writing JavaScript. The 3rd line finds all the “span” elements on the page that contain the word “Error” and then hides them. This might work too well so you need to make sure nothing else on the page is hidden as well that you don’t want hidden. The fourth line finds all the “div” elements that contain “Access denied”, but do not contain any other “div” elements, and hides them. This is crucial as I was unable to hide a “span” and had to use a “div” find and hide. However, since “div” tags are nested throughout this page without the caveat that makes sure the “div” tag doesn’t contain any nested “div” tags, this would have hidden most of the items on the page. The fifth line closes the script tag.

Tim Ferro

Trackbacks Comments
  • Queries says:

    Pls advise where should I post the above codes? Not working for me. Any update in code for jquery 1.6.2 version?

    Will appreciate your reply.

    • Sunil dubey says:

      Dear TEam,

      I am facing the same issue when we try restore the backup the error come “you don’t have permission to perform this action or access this resource at line :1 chart:15” I am using SharePoint foundation 2010.can anyone help me.
      Thanks

  • Cesar says:

    Thanks Tim, it works great for me…
    Nice pub

  • Sean says:

    Hi, I’m having an issue getting your script to work. Could you please have a look at my script and see if I’m doing anything wrong? I’ve confirmed the link the jquery is correct as I can use another script and it works (http://www.dhirendrayadav.com/2011/08/show-custom-error-message-instead-of.html), but I’m really interested in just hiding, not changing. Thank you very much.

    $(“span:contains(‘Error’)”).hide();
    $(“div:contains(‘Access denied’):not(:has(div))”).hide();

  • Sean says:

    Hi Tim, great site!
    The above article describes a solution I’ve been looking everywhere for, but for some reason I can’t get it to work. The only difference is that I’m running a newer version of jquery 1.7.2, on my own server but have also tried link to Google version. I’m also using SharePoint foundation.
    Any reason why it might now work?
    Thanks
    Sean

  • Matt Gudites says:

    Not sure what I’m doing wrong but this just is not working. I’ve got the latest version of jQuery on the server, and I’m referencing the correct path…access denied web parts still show on the page.

  • Sean K says:

    Hi, I ran across this blog post and it does exactly what I need to do, however try as I might I can’t get it to work. I’ve tried hosting the jQuery myself as well as using Googles, I’ve tried the lastest also the one you suggest, all with no luck. I know this tip is a year old but I’m using SharePoint 2010, is there any reason why it is not working?
    Thanks

  • Sar. says:

    This wasn’t working for me initially.
    I copied the code in notepad & replaced quotes & it worked like a charm.
    Something wrong with the code when you copy/paste from this page.

  • Fred says:

    For those wondering why this is not working there are a couple of things I did in order to get it to work.

    Firstly, don’t hide the CEWP. Simply turn off the Header. By default if it contains only HTML nothing will display. Hiding the WP will cause the code to not run when the page is loaded (thus defeating the purpose).

    Secondly, check the characters for quotes when you copy the above code. You may get ‘smart quotes’ that cause an issue.
    Below is the code that I used successfully (linked to Google’s JQuery). Simply cut and paste into a CEWP (be sure to edit the HTML source, not just paste the code into the CEWP):

    $(“span:contains(‘Error’)”).hide();
    $(“div:contains(‘Access denied’):not(:has(div))”).hide();

  • Tabares says:

    Very helpful, works very well.

    Thank you and best Regards.

  • Maunx says:

    You can hide the webpart. Just put the code in a document.ready function so that it loads when the page is loaded.New or old jquery doesn’t matter at all for this. It’s best placed in a CEWP below all the other web parts.

    $(document).ready(function() {

    $(“h3:contains(‘Error’)”).hide();
    $(“div:contains(‘Access denied’):not(:has(div))”).hide();
    });

  • Tommy Reynolds says:

    This is handy, Tim. However, it still left the web part and just hid the content inside which was rather ugly and would still show the error as you hover over. I improved it a bit, so thought I’d share (also using google CDN for jquery; no need to download locally):

    $(“div:contains(‘Access denied’):not(:has(div))”).parents(“.s4-wpcell-plain”).hide();

  • Tommy Reynolds says:

    Hmm.. my CDN reference was stripped out.

  • Jason says:

    Since IT doesn’t feel a need to enable audience targeting, wanted to try this out.

    I created a uploaded jQuery & a text file housing the script to a document library. Added a CWP to the page I’m trying to hide the web part on, used this method:

    http://sharepointadam.com/2010/08/31/insert-javascript-into-a-content-editor-web-part-cewp/

    But it still shows the web part I’m trying to hide, to other users with the error still attached.

    Is it possible for admins to disable Java/jQuery? I’m on the business side, so I don’t have full blown access to be a farm admin.

  • Lee McGhee says:

    Hey Tim, Hows everything. I might have to use you work around becuase Im having the same problem. Take it easy and later.

  • Jenn says:

    I just had to move the .CSS file to a Library where the users had permission.

  • Mike says:

    Has anyone tried this in SharePoint Foundation 2013?

  • Frank says:

    How worked for me:
    I used HTML Form Web Part
    Add the jscript path (place the file and press copy shortcut)
    Paste the code in script
    Replace smart quotes = replace ‘ and ”
    Hide the header and worked (Appearance – Chrome Type – None)
    Hide the web part is not necessary.

  • Tim says:

    Thanks for the script!

    It worked for me for sharepoint 2013 as well. I ended up to add the script as followed:

    $( document ).ready(function() {
    $(“span:contains(‘Error’)”).hide();
    $(“div:contains(‘Access denied’):not(:has(div))”).hide();
    });

    Cheers

    • Alex says:

      I had other jscode on the page.So this worked for me:

      $(“nobr:contains(‘Error’)”).hide();
      $(“div:contains(‘Access denied’):not(:has(div))”).hide();

      Thanks Tim

  • pieter says:

    Thank you for saving me some time !

Leave a Comment