Friday 6 January 2017

Things needs to be taken care while we are enabling anonymous access on SharePoint sites/Public facing sites

Hello Guys. I am back with new blog that is more relevant to things we need to take care when we enable anonymous search on our SharePoint site. In my current implementations I came through many various scenarios where SharePoint site will be available publicly. 

So here I am sharing my experience when we are enabling anonymous access to SharePoint site.

To enable rest query on List using anonymous user do execute bellow script in SharePoint Management Shell:

$site = Get-SPSite <<your anonymous site collection url>>$site.UpdateClientObjectModelUseRemoteAPIsPermissionSetting($false)
Reference URLhttps://blogs.msdn.microsoft.com/kaevans/2013/10/24/what-every-developer-needs-to-know-about-sharepoint-apps-csom-and-anonymous-publishing-sites/


To enable Get Items in SharePoint list for anonymous user do execute bellow script in SharePoint Management Shell:

$web = Get-SPWebApplication -Identity <<your anonymous site collection url>>
$web.ClientCallableSettings.AnonymousRestrictedTypes.Remove([Microsoft.SharePoint.SPList],"GetItems")$web.Update()
Reference URL : https://sharepointinaction.wordpress.com/2013/07/16/error-the-method-getitems-of-the-type-list-with-id-listss-guid-is-blocked-by-the-administrator-on-the-server/

Enable anonymous user search rest API please follow below steps:
  • Add your anonymous extended root site URL to content source.
  • Put content source on full crawl to which you have added your anonymous site url
  • Run below powershell commands
    • (Get-SPFarm).Id
    • (Get-SPSite <your root site collection url>).Id
    • (Get-SPWeb <your root site collection url>).Id
  • Create new blank text file using notepad named as queryparametertemplate.xml (please use notepad only because another editor may add some unwanted format to your file)
  • Copy/Paste below xml to newly created xml file in above step and replace guid with higlighted text in file: 
    <QueryPropertiesTemplate xmlns="http://www.microsoft.com/sharepoint/search/KnownTypes/2008/08" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
          <QueryProperties i:type="KeywordQueryProperties">
              <EnableStemming>true</EnableStemming>
              <FarmId>FARMID from command 1</FarmId>
              <IgnoreAllNoiseQuery>true</IgnoreAllNoiseQuery>
              <KeywordInclusion>AllKeywords</KeywordInclusion>
              <SiteId>SITEID from command 2</SiteId>
              <SummaryLength>180</SummaryLength>
              <TrimDuplicates>true</TrimDuplicates>
              <WcfTimeout>120000</WcfTimeout>
              <WebId>WEBID from command 3</WebId>
              <Properties xmlns:a="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
                  <a:KeyValueOfstringanyType>
                      <a:Key>_IsEntSearchLicensed</a:Key>
                      <a:Value i:type="b:boolean" xmlns:b="http://www.w3.org/2001/XMLSchema">true</a:Value>
                  </a:KeyValueOfstringanyType>
                  <a:KeyValueOfstringanyType>
                      <a:Key>EnableSorting</a:Key>
                      <a:Value i:type="b:boolean" xmlns:b="http://www.w3.org/2001/XMLSchema">true</a:Value>
                  </a:KeyValueOfstringanyType>
                  <a:KeyValueOfstringanyType>
                      <a:Key>MaxKeywordQueryTextLength</a:Key>
                      <a:Value i:type="b:int" xmlns:b="http://www.w3.org/2001/XMLSchema">4096</a:Value>
                  </a:KeyValueOfstringanyType>
                  <a:KeyValueOfstringanyType>
                      <a:Key>TryCache</a:Key>
                      <a:Value i:type="b:boolean" xmlns:b="http://www.w3.org/2001/XMLSchema">true</a:Value>
                  </a:KeyValueOfstringanyType>
              </Properties>
              <PropertiesContractVersion>15.0.0.0</PropertiesContractVersion>
              <EnableFQL>false</EnableFQL>
              <EnableSpellcheck>Suggest</EnableSpellcheck>
              <EnableUrlSmashing>true</EnableUrlSmashing>
              <IsCachable>false</IsCachable>
              <MaxShallowRefinementHits>100</MaxShallowRefinementHits>
              <MaxSummaryLength>185</MaxSummaryLength>
              <MaxUrlLength>2048</MaxUrlLength>
              <SimilarType>None</SimilarType>
              <SortSimilar>true</SortSimilar>
              <TrimDuplicatesIncludeId>0</TrimDuplicatesIncludeId>
              <TrimDuplicatesKeepCount>1</TrimDuplicatesKeepCount>
          </QueryProperties>
          <WhiteList xmlns:a="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
              <a:string>RowLimit</a:string>
              <a:string>SortList</a:string>
              <a:string>StartRow</a:string>
              <a:string>RefinementFilters</a:string>
              <a:string>Culture</a:string>
              <a:string>RankingModelId</a:string>
              <a:string>TrimDuplicatesIncludeId</a:string>
              <a:string>ReorderingRules</a:string>
              <a:string>EnableQueryRules</a:string>
              <a:string>HiddenConstraints</a:string>
              <a:string>QueryText</a:string>
              <a:string>QueryTemplate</a:string>
              <a:string>SelectProperties</a:string>
              <a:string>SourceID</a:string>
          </WhiteList>
      </QueryPropertiesTemplate>

      •  Go to your SharePoint root Site collection > Site Contents
      •  Create new document library named QueryPropertiesTemplate
      •  Upload your newly created xml queryparametertemplate.xml in above step into QueryPropertiesTemplate
      • Go to your anonymous site and add &QueryTemplatePropertiesUrl='spfile://webroot/queryparametertemplate.xml' at end of your search query for REST
      • If you are using SharePoint variation sites in your implementation then at each variation site create new document library QueryPropertiesTemplate and upload QueryPropertiesTemplate into it.
      That's it from my sides folks. Will update blog if I come through any other possibilities.

      Thanks !!!


      Thursday 7 April 2016

      Create user profile from AD using powershell

      Hi,

      After a long time. Coming to straight point, how do we create user profiles automatically for those AD users available.

      Case : During one of the implementation of my project I came through one scenario in which I need to get all AD users and iterate through it. Check if user profile exists for that AD user or not? If not create user profile for it. I am pasting my script here. Please find below powershell script :

      import-module activedirectory
      $users = Get-ADUser -Filter * -SearchBase "OU=TESTGroup,DC=YOURADFOREST,DC=COM"

      $spsite = new-object Microsoft.SharePoint.SPSite(<YOUR MY SITE HOST URL>)
      $context = [Microsoft.Office.Server.ServerContext]::GetContext($spsite)
      $pmanager = new-object Microsoft.Office.Server.UserProfiles.UserProfileManager($context)

      ForEach($user in $users)  
      {    
         Write-Output('' + $user.UserPrincipalName)
         $exists = $pmanager.UserExists($user.UserPrincipalName)
         if ($exists -eq $false)
         {
           Write-Output('Profile for this user is not created...')
           $pmanager.CreateUserProfile($user.UserPrincipalName)
           $up = $pmanager.GetUserProfile($user.UserPrincipalName)
           $up.CreatePersonalSite()
         }
      }

      Note: Prior to execute this script do test Get-ADUser, if it throws any error then you need to install AD feature. To do so you can use these 2 commands

      Import-Module ServerManager

      Add-WindowsFeature RSAT-AD-PowerShell

      In above given code snippet

      OU=TESTGroup, TESTGroup is group name.
      DC=YOURADFOREST YOURADFOREST is your forest name

      That's it from my side. Hope this helps needy one. Thanks.

      Sunday 5 July 2015

      How to use iframes in SharePoint 2013


      Hello Everyone.
      Yes after a long time I m back with SharePoint blogs again. But excited to highlight one of the new feature introduced in SharePoint 2013 i.e. IFrame support for SharePoint 2013.

      Now SP2013 supports directly IFrame component. I will guide you step by step :
      1. You need to create new entry of your domain into HTML Field Security :
        1. One can do this by simply navigating to Site Settings
        2. You can find HTML Field Security under Site Collection Administration
        3. Click on that and you will on HTML Field Security configuration page. Add your domain into allow iframes from this domain textbox and click Add. If it is already there then no need to add. After adding domain name click on Ok button.
      2. Now navigate to page where you want IFrame component
      3. Click on Settings > Edit Page
      4. Click on Add a WebPart link.
      5. From WebPart Gallerty select Media and Content type.
      6. Select Content Editor WebPart from there and click Add button
      7. After WebPart is added click on Click here to add new content link
      8. From ribbon select Edit Source option.
      9. Add embeded code or IFrame element here and click Ok button.
      10. Click on Stop Editing option from ribbon.

      That's it you can view content inside IFrame there. I hope you will find this post helpful. Will modify this post with live example later on. Thanks for reading this post. And will post more things soon.