⭐ If you would like to buy me a coffee, well thank you very much that is mega kind! : https://www.buymeacoffee.com/honeyvig Hire a web Developer and Designer to upgrade and boost your online presence with cutting edge Technologies
Showing posts with label sharepoint 2010. Show all posts
Showing posts with label sharepoint 2010. Show all posts

Sunday, July 22, 2012

SharePoint Search: How to exclude part of a page / partial page from being indexed by SharePoint Search?

What?

How to exclude part of a page / partial page from being indexed by SharePoint Search?
Out of the box, SharePoint provides a mechanism for excluding publishing pages from the search index by any number of criteria, but what if you want to exclude only parts of a page? This becomes useful when you have content on numerous pages that contains common keywords. 

Why?

Scenario 1:

For example, say you have a search results webpart in your page layout to display your latest press release: "Product A just announced". That means all the pages that are created using that page layout will have "Product A" in them.  When someone performs a search for "Product A" they will get back every page in your site that is created using that page layout, instead of just the press release and related product pages. To prevent this, we need to prevent SharePoint from indexing that content when it’s performing a crawl.

OR
Scenario 2:

You want to index a regular non-SharePoint web site. Usually, it’s your company’s public-facing web site. That site has common navigation on every page with terms such as Contact, Locations, Privacy Policy, About, etc. that you don’t want to be indexed. If it is indexed, every time a user types in "contact", they end up having every page on the site returned in the search results.
How?

Scenario 1:

Ref: My colleague Scott Tindall has built this control and blogged about it here

Web Control:

System.Web.UI.WebControls.Panel control would be a good model to build the search crawl exclusion control on. It allows you to easily drop it in the page layout using SharePoint Designer, and you can put other html and controls within it.  It is not good to  inherit from the Panel control though, because it adds unwanted ‘div’ tags to the rendered output. The key to the Panel control’s behavior are the following two attributes on the class: [ParseChildren(false), PersistChildren(true)]. These attributes allow the content within the control to persist as controls and not properties of this control.

User Agent:

The second part of the equation is knowing when to show or hide the contents of the web control. SharePoint gives us a way to identify that it’s performing a crawl through the UserAgent property of the http request by adding "ms search" to it.

Code:

  1. [ParseChildren(false), PersistChildren(true)]  
  2. public class SearchCrawlExclusionControl : WebControl  
  3. {  
  4.         private string userAgentToExclude;  
  5.   
  6.    public string UserAgentToExclude  
  7.    {  
  8.       get  
  9.       {  
  10.          return (string.IsNullOrEmpty(userAgentToExclude)) ? "ms search" : userAgentToExclude;  
  11.       }  
  12.       set  
  13.       {  
  14.          userAgentToExclude = value;  
  15.       }  
  16.    }  
  17.   
  18.    protected override void CreateChildControls()  
  19.    {  
  20.       string userAgent = this.Context.Request.UserAgent;  
  21.       this.Visible = (!string.IsNullOrEmpty(userAgent)) ? !userAgent.ToLower().Contains(UserAgentToExclude) : true;  
  22.       base.CreateChildControls();  
  23.    }  
  24. }  

Using It:

  1. <SearchUtil:SearchCrawlExclusionControl ID="SearchCrawlExclusionControl1" runat="server">  
  2.     <div>Some Content To Exclude</div>  
  3. </SearchUtil:SearchCrawlExclusionControl>  

Scenario 2:

Ref: Corey Roth has blogged about this trick here

Let's assume that we have the links "Contact Us" and "Privacy Policy" in the footer of the site.

Our goal here is to exclude the contact us and privacy policy links in the navigation from our search results. How do we do that? It’s pretty simple actually. Just put the content that you do not want indexed in a div tag with a class of noindex. Let’s look at the complete HTML of the home page..

  1. <html>  
  2. <head>  
  3.     <title>Super Neat Home Page</title>  
  4. </head>  
  5. <body>  
  6.     <div>  
  7.         Welcome to our awesome site. We are the best! <a href="test.html">Awesome Stuff</a>  
  8.         If you need to get a hold of us, click <a href="contactus.html">here</a>. Worried,  
  9.         we'll <a href="privacy.html">sell you out?</a>  
  10.     </div>  
  11.     <div class="noindex">  
  12.         <a href="contactus.html">Contact Us</a> <a href="privacy.html">Privacy Policy</a>  
  13.     </div>  
  14. </body>  
  15. </html>  

You can see that the Contact Us and Privacy Policy links are inside <div class=”noindex”>. You might have noticed that the body of the page also has links to these two pages.  We included these so that those pages would get indexed. Since the common navigation is excluded there was no way for the crawler to follow those links. This is something you will want toconsider when you are designing master pages because you will need to have at least one link to each page on the site somewhere.

The noindex class works great with FAST Search for SharePoint as well as with SharePoint 2010 Search.

It is a highly recommended approach to make use of the noindex attribute any time you want to index a non-SharePoint site, such as your public-facing company web site. By excluding redundant sections of the page, you make your search results much more usable.

SharePoint 2010 - Access denied for users that have full control on the site

Scenario:

  • Users get "Access Denied" over the whole site, despite having Full Control permission
  • Site Collection Administrators have no problem logging in
Explanation:

A SharePoint 2010 site that uses claims-based authentication has been extended to Intranet zone that uses AD as well as FBA. The site has number of users in the default owners and members groups.
All the site users always get access denied over the whole site even though they clearly have access to the site through the site groups.
Site Collection Administrators are allowed to access the site and have no problems logging in.
Resolution:


Make sure that all the Master page, CSS files, any other files that are required are published.
If there are files that are required in the master pages and are not published, users will get access denied even if they have full control on the site.
If you are ok with giving all authenticated users atleast road-only access to all files inorder to prevent the access denied problem, then you can try the below.
Add a new "User Policy" for the web application that allows "All Authenticated Users" the permissions "Full Read" on the desired zone.
To add a new User Policy:


Go to Central Administration
Click on Application Management
Click on Manage Web Applications

Choose the desired web application:


Click on "User Policy"


Click on "Add Users" to add a new User Policy:



Select the zone that you want to apply the new policy to. If you are not sure what to choose, leave the defaut value selected (All Zones) and cick next


Choose the permissions that you would like to give to the user(s) in this new user policy. If you do not want to give the user(s) full permission, choose "Full Read". This permission ensures that all the users in this policy can atleast access the site. Then click on "Browse" icon in the "Choose Users" area.


If you would ike to give All Authenticated Users / AD users / FBA users "Full Read" access, then choose the appropriate group(s).
In the next screens, click OK to get out of the wizard.
Your new user policy should be ready now.

Tuesday, January 24, 2012

SharePoint (Beginner) : FileNotFoundException

For a beginner developer in SharePoint 2010 (with no experience with older version of SharePoint), you might be coding some simple “Hello World!” as your first SharePoint application. You might create a new Windows Console Application Project from Visual Studio and copy some sample codes from somewhere and try to run it. So you hit the magical F5 button and your project compiles successfully. However, when the program tries to run, Visual Studio throws you an FileNotFoundException, like the image below.
SharePoint 2010: FileNotFoundException
SharePoint 2010: FileNotFoundException
You then might be searching for codes error, is the SharePoint service running, & etc and found out that everything is running fine. So what’s the error?
The solution to this is to check your project platform target. By default, Visual Studio platform target is 32-bit (x86). Note that SharePoint 2010 ONLY runs on a 64-bit (x64) platform. So, you couldn’t run a 32-bit program on a 64-bit SharePoint Server. Now, to change your project platform to 64-bit, follow the steps below:
  1. Right-click on your Project in the Solution Explorer pane in Visual Studio and select Propertise
  2. Go to the Build tab and select x64 OR Any CPU
  3. Save changes, rebuild and run your program again.
SharePoint 2010: FileNotFoundException - 2