Redirect Rule to Restrict Sitecore Admin

As a part of Security hardening on CD environments, Sitecore access on CD should be restricted. There are numerous way to achieve this. But in case you wish to perform it using redirect rules, here it is –

<rule name="Restrict Sitecore" stopProcessing="true" >
     <match url=".*" />​​
     <conditions>​​
      <add input="{URL}" pattern="^/sitecore//?.*" />​​
      <add input="{URL}" pattern="^/sitecore/service/?.*" negate="true" />​​
     </conditions>​​
     <action type="Redirect" url="/" appendQueryString="false" />​​
 </rule>

Explanation :

  • Condition 1 (“^/sitecore//?.*”)
    • It would match all urls that has /sitecore/ in it.
  • Condition 2 (“^/sitecore/service/?.*”)
    • It would skip all the urls that has /sitecore/service/. This is required to allow service related urls that might communicate to CM site for data flow.
  • Action (“/”)
    • Redirect to Home page

Note : If you have any pages that are using resources from Sitecore folder, please make sure it’s working especially forms.

Clear Sitecore 9 Forms data

Sitecore 9 has added forms feature and we do not need an external module anymore. While we all have been using this, I came across a requirement of deleting all forms data when we completed testing it.

This is a very common scenario, but currently there is no native feature to do so. I contacted Sitecore support for this and they informed that they will be adding this feature in coming version. But till then, we can clear forms data and it is pretty simple.

Sitecore manages all the data in instanceName_ExperienceForms database. It has two tables –

  • FormsEntry
    • It records all entries submitted for forms along with FormId
  • FieldData
    • It records all entered data values for all form fields along with FormEntryID from above table.

You can clear this data to clear form data. Here is a database script that you can use to delete data of

  • all forms
  • specific form
  • form in a date range

Just make sure you execute it on your instanceName_ExperienceForms database.

BEGIN TRANSACTION [ClearFormData]
  Declare @createdFrom DateTime
  Declare @createdTo DateTime
  Declare @formId uniqueidentifier 
  Set @createdFrom = '2019-05-20' -- set your from date here (Range include both these dates)
  Set @createdTo = '2019-05-21' -- set your to date here
  Set @formId = '3317432C-DF54-4E54-B92A-1BA9AAEA2294' -- form id in same format as this (remove '{}')

  BEGIN TRY

	Delete FieldData
	from FormEntry right join [FieldData]
	on [FormEntry].ID = [FieldData].[FormEntryID]
--	where FormItemID = @formId -- * Uncomment this line to delete data for a single form *
--	and (cast(Created as date) between @createdFrom and @createdTo) -- * Uncomment this line to delete for mentioned duration *

      Delete From [FormEntry]  
--	  where FormItemID = @formId -- * Uncomment this line to delete data for a single form *
--	and (cast(Created as date) between @createdFrom and @createdTo) -- * Uncomment this line to delete for mentioned duration *

      COMMIT TRANSACTION [ClearFormData]
  END TRY
  BEGIN CATCH
      ROLLBACK TRANSACTION [ClearFormData]
  END CATCH

Happy Coding !!

Sitecore 9 License Location

As a part of go live activity, I was supposed to update Sitecore license on different environments. Before Sitecore 9, it was a an easy task with license present at just one location (inside data folder).

But now with Sitecore 9, with addition of Xconnect and IdentityServer sites, updating license isn’t as simple as before. Here is a list of locations where Sitecore license sits in case you wish to change –

1. Sitecore

1.1) Website (~sc-webroot~\App_Data)

2. Xconnect site

2.1) Website (~xconnect-webroot~\App_Data)

2.2) Automation Engine (~xconnect-webroot~\App_Data\jobs\continuous\AutomationEngine\App_Data)

2.3) Index Worker (~xconnect-webroot~\App_Data\jobs\continuous\IndexWorker\App_data)

2.4) Processing Engine* (~xconnect-webroot~\App_Data\jobs\continuous\ProcessingEngine\App_Data)

3. Identity Server

3.1) Website* (~identity-webroot~\sitecoreruntime)

Note:

  • Point 2.4 and 3.1 applies to SC 9.1 instance.
  • For points 2.2, 2.3 and 2.4 (if applicable), you will need to manually restart the associated Windows service afterwards.

Happy coding !!