Saturday, October 17, 2020

DOS commands tips and tricks

Quick commands 

List the file names and save in text file

dir *.dll /b >files.txt

Friday, October 9, 2020

Sitecore PowerShell Extensions - Read all child items

The following script will read all the child items and display the item names after filtering them based on the template name.



Tuesday, September 29, 2020

Run Windows Apps in Administrator Mode by default

How to run Windows Apps in administrator mode by default?

Step 1
Click on the windows icon and type the app name you want to open in administrator mode by default in my case it was Notepad++ and right-click on the icon to open the file location. 


Step 2
Right-click on Notepad++ and open the properties and click on Advanced and check the Run as administrator. 



Saturday, August 29, 2020

Sitecore Content Security Policy Issue

Sitecore 9+ has added the Content Security Policy custom header in the web.config and this will block any API calls to other domains. 



Open web.config and look for customHeaders

<configuration>

<location path="sitecore">

    <system.webServer>

         <httpProtocol>

                <customHeaders>

                         <httpProtocol>

                                <customHeaders>

                                        <remove name="X-Content-Type-Options"/>

          <remove name="X-XSS-Protection"/>

<remove name="Content-Security-Policy"/>

<add name="X-XSS-Protection" value="1; mode=block"/>

<add name="X-Content-Type-Options" value="nosniff "/>

<add name="Content-Security-Policy" value="default-src 'self' 'unsafe-inline' 'unsafe-eval' https://apps.sitecore.net; img-src 'self' data:; style-src 'self' 'unsafe-inline' https://fonts.googleapis.com; font-src 'self' 'unsafe-inline' https://fonts.gstatic.com; upgrade-insecure-requests; block-all-mixed-content;"/>

        </customHeaders>

      </httpProtocol>

   </system.webServer>

</location>

</configuration>


Now lets add other domain https://mydomain.com  in CSP.

<configuration>

<location path="sitecore">

    <system.webServer>

         <httpProtocol>

                <customHeaders>

                         <httpProtocol>

                                <customHeaders>

                                        <remove name="X-Content-Type-Options"/>

           <remove name="X-XSS-Protection"/>

<remove name="Content-Security-Policy"/>

<add name="X-XSS-Protection" value="1; mode=block"/>

<add name="X-Content-Type-Options" value="nosniff "/>

<add name="Content-Security-Policy" value="default-src 'self' 'unsafe-inline' 'unsafe-eval' https://apps.sitecore.net https://mydomain.com; img-src 'self' data:; style-src 'self' 'unsafe-inline' https://fonts.googleapis.com; font-src 'self' 'unsafe-inline' https://fonts.gstatic.com; upgrade-insecure-requests; block-all-mixed-content;"/>

        </customHeaders>

      </httpProtocol>

   </system.webServer>

</location>

</configuration>


Thursday, August 20, 2020

Sitecore Config Patch Files

Here is the collection of Sitecore Patch files I have used.


1. Patch Config to Enable/disable the xDB and the tracker


2. Patch Config to Enable/disable the CDN 

Monday, August 17, 2020

Sitecore PowerShell Extensions - Update Placeholders

The following script reads all child items under the Home node and changes the placeHolder key as per the per defined mapping (old and new) if the rendering type is "JSON rendering"

references:

  1. https://www.kasaku.co.uk/2018/02/28/updating-rendering-placeholders/
  2. https://doc.sitecorepowershell.com/

Sitecore PowerShell - Update Rendering Caching

Following scripts reads all renderings in "/sitecore/layout/Renderings/Project/Feature/Platform" path and updates the caching checkbox Cacheable and VaryByData for all the rendering of "Json Rendering" type.


Sunday, July 19, 2020

Add custom user agent in chrome

To override the user agent string from Chrome DevTools:
  1. Press Command+Shift+P (Mac) or Control+Shift+P (Windows, Linux, Chrome OS) to open the Command Menu.
    The Command Menu.
    Figure 1. The Command Menu
  2. Type network conditions, select Show Network conditions, and press Enter to open the Network conditions tab.
  3. In the User agent section disable the Select automatically checkbox.
    Disabling 'Select automatically'.
    Figure 2. Disabling Select automatically
  4. Select a user agent string from the list, or enter your own custom string.

Monday, June 1, 2020

How to expose localhost Sitecore instance to the Internet

How to expose localhost Sitecore instance to the Internet?
In many cases, it's required you to expose your localhost Sitecore instance to the Internet for testing, integration with APIs, or other third parties.

There are so many secure tunnels, reverse proxy providers to which we can use to expose your localhost Sitecore instance to the internet.

You can use anyone from the following tunneling provider and can expose your localhost to the internet.

  1. http://serveo.net/ - In this blog, I will be using Serveo to expose my local Sitecore instance. 
  2. https://localhost.run/ 
  3. https://ngrok.com/

Setup a local Sitecore instance with Serveo. 

  1. Check local Sitecore instance IIS binding, in my demo its "sc825.local.com"

  2. Check our host file have an entry for your local Sitecore instance (you can find your host file C:\Windows\System32\drivers\etc)


  3. Now let's bind our local Sitecore instance to Serveo.
    Open CMD Prompt in Administrator mode and run the following command 
    ssh -R 80:sc825.local.com:80 serveo.netServeo will create one dynamically generated subdomain to route traffic from internet to your local Sitecore instance(in my case its  sc825.local.com)

  4. Now traffic will start flowing to your IIS using this dynamically generated subdomain but incoming HTTP requests will be having the host as "novitas.serveo.net", so we need to update site definition in Sitecore configuration using a patch file



  5. Add site binding in IIS for the dynamically generated subdomain ( in my case its https://novitas.serveo.net)


  6. We are done! Now restart your IIS and make sure your connection with Serveo is still alive in CMD Prompt. Browser your site using dynamically generated subdomain ( in my case its https://novitas.serveo.net)