Show custom error message instead of Web part access denied – SharePoint 2010

Many times while using “ListViewWebPart” you get the following error if the user does not have access to the list/library
Error Web Part Error: Access denied. You do not have permission to perform this action or access this resource”
Though the error is kind of explanatory but is not very user friendly. I have getting demands from lot of customers to replace this error with a custom error message. Let us see how we can achieve this using Jquery
1. Download latest version of Jquery
2. Edit Page where you have added you ListViewWebPart and add a “Content Editor Web part” at the end of the page. Make the web part hidden
3. Add the following JavaScript to the “Content Editor Web Part”

<script type="text/javascript" src="/Shared%20Document/jquery.js"></script>
<script type="text/javascript">
function() {
$('div[errorwebpart="1"]').text('The content of this section is restricted to authorized users only.');

Note: the path for the Jquery should be your path for the Jquery file

Once done you will be able to see the custom message instead of generic Sharepoint message


Access is denied : Crawling SharePoint Content

You might get a access denied error while crawling a SharePoint content source something like below
Access is denied. Verify that either the Default Content Access Account has access to this repository, or add a crawl rule to crawl this repository. If the repository being crawled is a SharePoint repository, verify that the account you are using has “Full Read” permissions on the SharePoint Web Application being crawled. (The item was deleted because it was either not found or the crawler was denied access to it.)
Please follow the following steps to resolve the issue
1.Make sure that the “Default Content Access” account is not an in-built account like local system, network service etc
2. Make sure that the content access account has proper access (read) to the content databases and shared service databases
3.If you are using FQDN for your site add a DisableLoopBackCheck in registry
  1. Click Start, click Run, type regedit, and then click OK.
  2. Locate and then click the following registry subkey:HKEY_LOCAL_MACHINESYSTEMCurrentControlSetControlLsa
  3. Right-click Lsa, point to New, and then click DWORD Value.
  4. Type DisableLoopbackCheck, and then press ENTER.
  5. Right-click DisableLoopbackCheck, and then click Modify.
  6. In the Value data box, type 1, and then click OK.
  7. Exit Registry Editor.
  8. Restart the computer.