Illegal Characters in Path Sitecore

Instead of redirecting to the "Item Not Found" page, Sitecore may generate the following error messages when it receives a request containing Illegal characters in the path:

ERROR Application error.
Exception: System.ArgumentException
Message: Illegal characters in path.
Source: mscorlib
at System.IO.LongPathHelper.Normalize(String path, UInt32 maxPathLength, Boolean checkInvalidCharacters, Boolean expandShortPaths)
at System.IO.Path.NormalizePath(String path, Boolean fullCheck, Int32 maxPathLength, Boolean expandShortPaths)
at System.IO.Path.GetFullPathInternal(String path)
at System.Security.Util.StringExpressionSet.CanonicalizePath(String path, Boolean needFullPath)
at System.Security.Util.StringExpressionSet.CreateListFromExpressions(String[] str, Boolean needFullPath)
at System.Security.Permissions.FileIOPermission.AddPathList(FileIOPermissionAccess access, AccessControlActions control, String[] pathListOrig, Boolean checkForDuplicates, Boolean needFullPath, Boolean copyPathList)
at System.Security.Permissions.FileIOPermission..ctor(FileIOPermissionAccess access, String path)
at System.Web.InternalSecurityPermissions.PathDiscovery(String path)
at System.Web.HttpRequest.get_PhysicalPath()
at Sitecore.Web.XFrameOptionsHeaderModule.IsSitecoreFolderRequest(HttpContextBase httpContext)
at Sitecore.Web.XFrameOptionsHeaderModule.BeginRequestHandler(Object sender, EventArgs e)
at System.Web.HttpApplication.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step)
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
view raw gistfile1.txt hosted with ❤ by GitHub

Solution:

I saw a similar issue and it could depend on the "requestPathInvalidCharacters" settings in <httpRuntime> in Web.config.

  1. Go to the web.config and search for httpRuntime node.
  2. Check if the requestValidationMode is there, if it is not then add the attribute requestValidationMode="2.0" 
  3. Make sure validateRequest attribute in the page node is set to false.
    <pages validateRequest="false">
  4. If you want to add these characters to the path, add the requestPathInvalidCharacters attribute to the httpRuntime node.
    <httpRuntime targetFramework="4.8" ...... requestPathInvalidCharacters="&lt;,&gt;,*,%,&amp;,:,\,?"/>
azure-cdn-sitecore

Reference:

Happy Sitecoreing 😊

Comments

Popular posts from this blog

Sitecore Installation Error: Failed to Start Service 'Sitecore Marketing Automation Engine'

Import CSV Data in Sitecore Using PowerShell: Part-3

Error: Method Through Reflection is Not Allowed after Applying Sitecore Hotfix