Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Ras 66 posts 330 karma points
    Oct 12, 2021 @ 12:12
    Ras
    0

    500 page is returned where a 404 page should be returned

    Hi, I've set up my custom error pages as such in my web config files:

        <httpErrors errorMode="Custom" existingResponse="Replace" xdt:Transform="InsertIfMissing">
            <remove statusCode="404" subStatusCode="-1" xdt:Transform="InsertIfMissing"/>
            <remove statusCode="500" subStatusCode="-1" xdt:Transform="InsertIfMissing"/>
    
            <error statusCode="404" prefixLanguageFilePath="" path="/1227" responseMode="ExecuteURL" xdt:Transform="InsertIfMissing" />
            <error statusCode="500" prefixLanguageFilePath="" path="/1230" responseMode="ExecuteURL" xdt:Transform="InsertIfMissing" />
        </httpErrors>
    

    However a 500 page is returned in every case, even where a 404 page should be returned. Both of the ID's in the path="" are ID's of my 404 and 500 pages respectively, in the backoffice.

    In the log viewer I get this error:

    System.InvalidOperationException: Sequence contains no elements
       at System.Linq.Enumerable.First[TSource](IEnumerable`1 source)
       at Umbraco.Core.Configuration.UmbracoSettings.ContentErrorsElement.get_Error404Collection() in D:\a\1\s\src\Umbraco.Core\Configuration\UmbracoSettings\ContentErrorsElement.cs:line 13
       at Umbraco.Core.Configuration.UmbracoSettings.ContentElement.get_Error404Collection() in D:\a\1\s\src\Umbraco.Core\Configuration\UmbracoSettings\ContentElement.cs:line 17
       at Umbraco.Web.Routing.ContentFinderByConfigured404.TryFindContent(PublishedRequest frequest) in D:\a\1\s\src\Umbraco.Web\Routing\ContentFinderByConfigured404.cs:line 57
       at Umbraco.Web.Routing.PublishedRouter.HandlePublishedContent(PublishedRequest request) in D:\a\1\s\src\Umbraco.Web\Routing\PublishedRouter.cs:line 459
       at Umbraco.Web.Routing.PublishedRouter.FindPublishedContentAndTemplate(PublishedRequest request) in D:\a\1\s\src\Umbraco.Web\Routing\PublishedRouter.cs:line 398
       at Umbraco.Web.Routing.PublishedRouter.PrepareRequest(PublishedRequest request) in D:\a\1\s\src\Umbraco.Web\Routing\PublishedRouter.cs:line 131
       at Umbraco.Web.UmbracoInjectedModule.ProcessRequest(HttpContextBase httpContext) in D:\a\1\s\src\Umbraco.Web\UmbracoInjectedModule.cs:line 134
       at Umbraco.Web.UmbracoInjectedModule.<Init>b__18_4(Object sender, EventArgs e) in D:\a\1\s\src\Umbraco.Web\UmbracoInjectedModule.cs:line 414
       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)
    

    Any advice how to move forward?

  • Huw Reddick 1929 posts 6717 karma points MVP 2x c-trib
    Oct 14, 2021 @ 13:26
    Huw Reddick
    0

    your 404 should be set up in config\umbracosettings.config, as it is handled by Umbraco, then set up your other error handling like below (you need both sets for it to work correctly)

      <system.web>
        <customErrors mode="On" redirectMode="ResponseRewrite" defaultRedirect="/errorHandler">
          <error statusCode="500" redirect="/errorHandler" />
        </customErrors>
    </system.web>
    
      <system.webServer>
        <httpErrors errorMode="Custom" existingResponse="Replace">
          <remove statusCode="404" />
          <remove statusCode="500" />
          <error statusCode="404" prefixLanguageFilePath="" path="/error404" responseMode="ExecuteURL" />
          <error statusCode="500" prefixLanguageFilePath="" path="/errorHandler" responseMode="ExecuteURL" />
        </httpErrors>
    </system.webServer>
    

    set the paths to whatever your path should be

Please Sign in or register to post replies

Write your reply to:

Draft