network sxastarter_default was found but has incorrect label com.docker.compose.network set to ""

You might have faced an error while making the container up using the up.ps1 script, and subsequently, when attempting to run docker compose down followed by docker compose up. This mostly happens when you make the containers up and then containers creates the network but you don't down them gracefully, or don't use down command before shutting down your system.

To resolve this problem, follow these steps:

1. Run docker network ls to show all the available networks.


2. If you want to remove specific network use the command docker network rm <network Id> to remove the network causing issue in the up containers, which in our case is sxastarter_default.


Run docker network prune to remove all networks. Note: This command will delete all unused networks on your system.

3. Open command prompt and stop IIS by command iisreset /stop

4. Check in the services if there is any solr service using port 8984 (mostly in the docker-compose file this is the port used untill you did not change it) and stop that service.

5. Once the network deletion is complete, run docker compose up -d or ./up.ps1 to start the containers.

The issue should be resolved, and it should work fine.

6. If after 2nd point you get an error that endpoint is already is in use and unable to delete the network then down your containers -> init.ps1 -> up.ps1.


Reference: https://alvaropmontenegro.com/2024/05/31/sitecore-xm-cloud-local-setup-errors/ 

Thanks!

sitecore reset admin password to b

 If you forgot the admin password in the sitecore and want to reset to b then follow the below steps using sql server.

Open the new query window using the Core db and run the following script:



UPDATE 
    [aspnet_Membership] 
SET 
    [Password]='qOvF8m8F2IcWMvfOBjJYHmfLABc=', 
    [PasswordSalt]='OM5gu45RQuJ76itRvkSPFw==', 
    [IsApproved] = '1', 
    [IsLockedOut] = '0'
WHERE 
    UserId IN (
        SELECT UserId FROM dbo.aspnet_Users WHERE UserName = 'sitecore\Admin'
    ) 

Thanks!

sitecore site in unreachable

When you install the Sitecore site locally and get the following error something like shown in SS below, after successful installation, obviously your site will not be support.cloudflare.com but will be something like https://yoursitesc.dev.local/


This means that the issue is because of the certificate. So, you will need to install the self signed certificate which should not take more than 2 minutes. Follow the article https://sitecorepeanuts.blogspot.com/2024/06/sitecore-self-signed-certificate.html to create a self signed certificate for your
1. Sitecore site
2. Identity site
3. xConnect site

Then again try after restarting the IIS.

Thanks!


The container operating system does not match the host operating system

 When you get the following error while making the containers up

docker: Error response from daemon: hcs::CreateComputeSystem 377c5ba81cdccd9cf8217251aba4171ca3bd6a593f14db12c3ae6ead394530c3: The container operating system does not match the host operating system.

Solution:

Windows 10 OS on AVD runs within Windows Server. As a result, docker desktop engine detects the Product Type as 3 which means VER_NT_SERVER (Windows Server). The default isolation is ‘Process’ for windows server, hence the docker throws the incompatible host OS.


What' the work around?


Set isolation type to hyerv.


{

"exec-opts": ["isolation=hyperv"],

"experimental": false

}



Thanks!


sitecore self signed certificate

 To create a self signed certificate for sitecore domain in the local use following command in PS.

New-SelfSignedCertificate -CertStoreLocation Cert:\LocalMachine\My -DnsName "habitat93.local.com" -FriendlyName "habitat93.local.com" -NotAfter (Get-Date).AddYears(10)

After this ensure to check the check box Require Server Name Indication. Otherwise, same certificate will be assigned to other hostnames as soon as you create new hostname for the site.


Thanks!

failed to create endpoint sxastarter-solr-1 on network sxastarter_default

The error shown in the SS below happens due to port collision.

check in your docker compose file which port is mentioned to use for solr service

And to verify that all ports mentioned in docker-compose.yml is not in use by any other process follow the below steps

  1. run iisreset /stop command from powershell
  2. netstat -aon | findstr 8984 to check if any port is being used by windows service
Most of the time it happens that solr service will be using this port if you have installed the solr in your machine in the past.
If this is solr then stop the solr service or in case you found other service then stop it in the services.msc and now again try .\up.ps1

It should work fine.

Thanks!

network sxastarter_default was found but has incorrect label com.docker.compose.network set to ""

Follow the below step to resolve the issue shown in the SS below:




  1. docker network ls
  2. docker network rm <network id of sxastarter_default>
  3. docker compose up -d
It will give you the exact issue as in our case it was that mounting was not right for license file.
4. Fix the issue, in our case it was correct file path and try docker compose up -d
5. Now run .\up.ps1

Thanks!!

Sitecore media upload with user friendly dialogue message

When we upload the media in the Sitecore media library then it happens that sometimes an issue occurs but the error message is not that friendly which can help an author/developer to know what the exact issue is. 

The same situation once was in Nehemiah Jeyakumar so I took help from his blog https://www.nehemiahj.com/2022/07/sitecore-media-upload-dialog-duplicate.html to implement the functionality for our project as well.

Here we created our own version of the UploadMedia2.aspx that is responsible for showing the dialogue on uploading the media in the media library.

The UploadMedia2.aspx lives in folder C:\inetpub\wwwroot\yourProject\sitecore\shell\Applications\Media\Upload Media


Below is the code that we wrote for this aspx

<%@ Page language="c#" Codebehind="UploadMedia2.aspx.cs" AutoEventWireup="false" Inherits="MyProject.Feature.Media.sitecore.shell.Applications.Media.UploadMedia.UploadMediaPage2" %>
<%@ OutputCache Location="None" VaryByParam="none" %>

and code behind is:

using Sitecore;
using Sitecore.Configuration;
using Sitecore.Data;
using Sitecore.Diagnostics;
using Sitecore.Exceptions;
using Sitecore.Globalization;
using Sitecore.Pipelines;
using Sitecore.Pipelines.Upload;
using Sitecore.Shell.Web.UI;
using Sitecore.Web.UI.XmlControls;
using System;
using System.Web;
using System.Web.UI;

namespace MyProject.Feature.Media.sitecore.shell.Applications.Media.UploadMedia
{
  /// <summary>
  /// Upload Media Page 2 
  /// </summary>
  public class UploadMediaPage2 : SecurePage
  {
    protected override void OnInit(EventArgs e)
    {
      Control control = ControlFactory.GetControl("UploadMedia");
      if (control != null)
      {
        Controls.Add(control);
      }
      base.OnInit(e);
    }

    protected override void OnLoad(EventArgs e)
    {
      base.OnLoad(e);
      if (base.MaxRequestLengthExceeded)
      {
        Log.Error($"Uploaded file is too big. Stack Trace: failed on if condition of RSM.Feature.Media.sitecore.shell.Applications.Media.UploadMedia.UploadMediaPage2", this);
        HttpContext.Current.Response.Write("<html><head><script type=\"text/JavaScript\" language=\"javascript\">window.top.scForm.getTopModalDialog().frames[0].scForm.postRequest(\"\", \"\", \"\", 'ShowFileTooBig()')</script></head><body>Done</body></html>");
      }
      else
      {
        if (base.IsEvent || base.Request.Files.Count <= 0)
        {
          return;
        }
        try
        {
          string empty = string.Empty;
          Language contentLanguage = Sitecore.Context.ContentLanguage;
          string text = Sitecore.Context.ClientPage.ClientRequest.Form["ItemUri"];
          ItemUri itemUri = ItemUri.Parse(text);
          if (itemUri != null)
          {
            empty = itemUri.GetPathOrId();
            contentLanguage = itemUri.Language;
            UploadArgs uploadArgs = new UploadArgs
            {
              FileOnly = false,
              Files = base.Request.Files,
              Folder = empty,
              Overwrite = Settings.Upload.SimpleUploadOverwriting,
              Unpack = false,
              Versioned = Settings.Media.UploadAsVersionableByDefault,
              Language = contentLanguage,
              CloseDialogOnEnd = false,
              Destination = (Settings.Media.UploadAsFiles ? UploadDestination.File : UploadDestination.Database)
            };
            Pipeline pipeline = PipelineFactory.GetPipeline("uiUpload");
            pipeline.Start(uploadArgs);
            if (uploadArgs.UploadedItems.Count > 0)
            {
              empty = uploadArgs.UploadedItems[0].ID.ToString();
              Log.Audit(this, "Upload: {0}", StringUtil.Join(uploadArgs.UploadedItems, ", ", "Name"));
            }
            else
            {
              empty = string.Empty;
            }
            if (string.IsNullOrEmpty(uploadArgs.ErrorText))
            {
              HttpContext.Current.Response.Write("<html><head><script type=\"text/JavaScript\" language=\"javascript\">window.top.scForm.getTopModalDialog().frames[0].scForm.postRequest(\"\", \"\", \"\", 'EndUploading(\"" + empty + "\")')</script></head><body>Done</body></html>");
            }
            return;
          }
          Sitecore.Exceptions.SecurityException ex = new Sitecore.Exceptions.SecurityException("Upload ItemUri invalid");
          Log.Error("ItemUri not valid. ItemUri: " + text, ex, this);
          throw ex;
        }
        catch (OutOfMemoryException)
        {
          Log.Error($"Uploaded file is too big. Stack Trace: failed on OutOfMemoryException catch block of RSM.Feature.Media.sitecore.shell.Applications.Media.UploadMedia.UploadMediaPage2", this);
          HttpContext.Current.Response.Write("<html><head><script type=\"text/JavaScript\" language=\"javascript\">window.top.scForm.getTopModalDialog().frames[0].scForm.postRequest(\"\", \"\", \"\", 'ShowFileTooBig(" + StringUtil.EscapeJavascriptString(base.Request.Files[0].FileName) + ")')</script></head><body>Done</body></html>");
        }
        catch (Exception ex3)
        {
          if (ex3.InnerException is OutOfMemoryException)
          {
            Log.Error($"Uploaded file is too big. Stack Trace: failed on OutOfMemoryException with ex3 catch block of RSM.Feature.Media.sitecore.shell.Applications.Media.UploadMedia.UploadMediaPage2", this);
            HttpContext.Current.Response.Write("<html><head><script type=\"text/JavaScript\" language=\"javascript\">window.top.scForm.getTopModalDialog().frames[0].scForm.postRequest(\"\", \"\", \"\", 'ShowFileTooBig(" + StringUtil.EscapeJavascriptString(base.Request.Files[0].FileName) + ")')</script></head><body>Done</body></html>");
          }
          else if (ex3.InnerException is DuplicateItemNameException)
          {
            Log.Error($"File with same name already exist.", this);
            HttpContext.Current.Response.Write("<html><head><script type=\"text/JavaScript\" language=\"javascript\">window.top.scForm.getTopModalDialog().frames[0].scForm.postRequest(\"\", \"\", \"\", 'ShowUploadError(\"" + "The item with same name is already defined on this level.\"" + ", " + StringUtil.EscapeJavascriptString(base.Request.Files[0].FileName) + ")')</script></head><body>Done</body></html>");
          }
          else
          {
            Log.Error($"An error occured while uploading the media. The exception is {ex3.Message}", this);
            HttpContext.Current.Response.Write("<html><head><script type=\"text/JavaScript\" language=\"javascript\">window.top.scForm.getTopModalDialog().frames[0].scForm.postRequest(\"\", \"\", \"\", 'ShowError')</script></head><body>Done</body></html>");
          }
        }
      }
    }
  }
}

Now replace the existing UploadMedia2.aspx with your version and check according to the exception the media dialogues will show the user-friendly messages.


For more info with screenshots please check this helpful blog https://www.nehemiahj.com/2022/07/sitecore-media-upload-dialog-duplicate.html

Thanks!!

Sitecore media upload with specific file extensions

 We had a requirement to upload files in the media library but certain file extensions like .exe, and .ps1 are to be blocked, giving the customer flexibility in the future they can have the flexibility to enter the extension in the config file that is to be blocked or allowed.

So we have an uploadProcessor that we created as follows:

using Sitecore.Diagnostics;
using Sitecore.Pipelines;
using Sitecore.Pipelines.Upload;
using Sitecore.Zip;
using System.Collections.Generic;
using System.IO;
using System.Web;

namespace MyProject.Feature.Media
{
  public class MediaFilter : UploadProcessor
  {
    private bool _isAllowed;

    private string _extensions;

    public MediaFilter(string allowed, string blocked)
    {
      if (!string.IsNullOrEmpty(allowed))
      {
        _isAllowed = true;
        _extensions = allowed.Replace(" ", "").ToLower();
      }
      else if (!string.IsNullOrEmpty(blocked))
      {
        _isAllowed = false;
        _extensions = blocked.Replace(" ", "").ToLower();
      }
    }

    public void Process(UploadArgs args)
    {
      Assert.ArgumentNotNull((object)args, "args");
      if (string.IsNullOrEmpty(_extensions))
      {
        return;
      }
      List<string> list = PrepareExtensions(_extensions);
      foreach (string file in args.Files)
      {
        HttpPostedFile httpPostedFile = args.Files[file];
        if (string.IsNullOrEmpty(httpPostedFile.FileName))
        {
          continue;
        }
        if (UploadProcessor.IsUnpack(args, httpPostedFile))
        {
          ZipReader val = new ZipReader(httpPostedFile.InputStream);
          try
          {
            foreach (ZipEntry entry in val.Entries)
            {
              string text = Path.GetExtension(entry.Name.ToLower()).TrimStart('.');
              bool flag = list.Contains(text);
              if ((!_isAllowed || !flag) && ((!_isAllowed && flag) || (_isAllowed && !flag)))
              {
                HttpContext.Current.Response.Write("<script type=\"text/JavaScript\">alert(\"Uploading files with ." + text + " extension is restricted\");</script>");
                Log.Audit($"Upload restricted: {entry.Name}", (object)this);
                new Done().Process(args);
                ((PipelineArgs)args).AbortPipeline();
                return;
              }
            }
          }
          finally
          {
            httpPostedFile.InputStream.Position = 0L;
          }
        }
        string text2 = Path.GetExtension(httpPostedFile.FileName.ToLower()).TrimStart('.');
        bool flag2 = list.Contains(text2);
        if ((!_isAllowed || !flag2) && ((!_isAllowed && flag2) || (_isAllowed && !flag2)))
        {
          HttpContext.Current.Response.Write("<script type=\"text/JavaScript\">alert(\"Uploading files with ." + text2 + " extension is restricted\");</script>");
          Log.Audit($"Upload restricted: {httpPostedFile.FileName}", (object)this);
          new Done().Process(args);
          ((PipelineArgs)args).AbortPipeline();
          break;
        }
      }
    }

    private List<string> PrepareExtensions(string csvExtensions)
    {
      string[] array = csvExtensions.Split(',');
      List<string> list = new List<string>();
      string[] array2 = array;
      foreach (string item in array2)
      {
        list.Add(item);
      }
      return list;
    }
  }
}

Then we have the respective config file as 

<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
    <sitecore>
        <processors>
            <uiUpload>
                <processor mode="on" type="MyProject.Feature.Media.MediaFilter, MyProject.Feature.Media" patch:before="*[1]">
                    <param name="allowed" desc="Allowed extensions (comma separated)"></param>
                    <param name="blocked" desc="Blocked extensions (comma separated)">exe,dll,bat</param>
                </processor>                
            </uiUpload>
        </processors>       
    </sitecore>    
</configuration>

So after this, we had one more requirement to edit the error message at the time of uploading the media so that a user-friendly message can be generated if while uploading we get any error. This is covered on the link https://sitecorepeanuts.blogspot.com/2024/06/sitecore-media-upload-with-user.html to avoid the lengthy article and keep the context separate.

Creating Solr core for sitecore using command prompt

We setup the solr cores using command “C:\solr8985\sc103solr-8.11.2\bin>solr.cmd create -c sitecore_sxa_web_index -d sitecore_configset” ...