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/
I would like to share the things that can provide information or help someone to achieve something. I research, I practice then I share. Please leave your comment if I can do better for you.
sitecore site in unreachable
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
}
sitecore self signed certificate
To create a self signed certificate for sitecore domain in the local use following command in PS.
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
- run iisreset /stop command from powershell
- netstat -aon | findstr 8984 to check if any port is being used by windows service
network sxastarter_default was found but has incorrect label com.docker.compose.network set to ""
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.
Troubleshoot personalization on xm cloud
Here are the troubleshooting steps below that helped personalization to work. We checked the events analytics in the page builder but it was...
-
In this, we will check if the user exists and make him log in otherwise give an error. There is one Register button also that redirects to ...
-
You have to set the following configuration to true to get the detailed information on rendering parameters set. < configuration xmlns:p...
-
I hope you would have seen the article already regarding the wildcard using item resolver before reading this. So, to resolve the wildcar...