404 custom page in sitecore from content tree

I have a multilingual site, and I want the 404 user page in all languages ​​to depend on the site context. What is the right approach to get the 404 page defined in the content tree or to access the 404 page from the data tree? I can get 404 pages if I define this in the root of my site, but not from the data tree.

enter image description here

I want a 404 page from the content tree as my 404 custom redirect.

My webconfig settings:

<setting name="ItemNotFoundUrl" value="/404Page.aspx" />

IIS 404. enter image description here

The error I received when there is no page in sitecore:

After changing the default IIS and setting httpErrors like    

  <error statusCode="404" path="/404PAGE.aspx" responseMode="ExecuteURL" />

</httpErrors>

enter image description here

+4
source share
4 answers

ExecuteRequest httpBeginRequest.
404 .

RedirectOnItemNotFound 404 .

, , .

EDIT: , , 404 .

, 404 :

:

<setting name="NotFoundPage.SiteName1" value="/not-found.aspx" />
<setting name="NotFoundPage.SiteName2" value="/not-found.aspx" />

RedirectOnItemNotFound , 404 :

public class ExecuteRequest : Sitecore.Pipelines.HttpRequest.ExecuteRequest
{
    protected override void RedirectOnItemNotFound(string url)
    {
        var context = System.Web.HttpContext.Current;

        try
        {
            // Get the domain of the current request.
            string domain = context.Request.Url.GetComponents(UriComponents.Scheme | UriComponents.Host, UriFormat.Unescaped);

            // Get 'not found page' setting for current site.
            string notFoundUrl = Sitecore.Configuration.Settings.GetSetting(string.Conact("NotFoundPage.", Sitecore.Context.Site.Name));

            // Request the contents of the 'not found' page using a web request.
            string content = Sitecore.Web.WebUtil.ExecuteWebPage(string.Concat(domain, notFoundUrl));

            // Send the content to the client with a 404 status code
            context.Response.TrySkipIisCustomErrors = true;
            context.Response.StatusCode = 404;
            context.Response.Write(content);
        }
        catch (Exception)
        {
            // If our plan fails for any reason, fall back to the base method
            base.RedirectOnItemNotFound(url);
        }

        // Must be outside the try/catch, cause Response.End() throws an exception
        context.Response.End();
    }
}

, , .
, , ...

EDIT 2: ​​ :

<pipelines>
  <httpRequestBegin>
    <processor type="Sitecore.Pipelines.HttpRequest.ExecuteRequest, Sitecore.Kernel">
      <patch:attribute name="type">ParTech.Pipelines.ExecuteRequest, ParTech</patch:attribute>
    </processor>
  </httpRequestBegin>
</pipelines>
+6

ItemNotFoundUrl Sitecore , , , , ( ). :

<setting name="ItemNotFoundUrl" value="/errors/404.aspx" />
<setting name="LayoutNotFoundUrl" value="/errors/500.aspx"/>
<setting name="NoAccessUrl" value="/errors/403.aspx"/>

Techphoria414 , Sitecore 404 SEO , 302 . , true : Server.Transfer:

<!--  USE SERVER-SIDE REDIRECT FOR REQUEST ERRORS
    If true, Sitecore will use Server.Transfer instead of Response.Redirect to redirect request to service pages when an error occurs (item not , access denied etc).
    Default value: false
-->
<setting name="RequestErrors.UseServerSideRedirect" value="true"/>

ExecuteRequest.

protected virtual void PerformRedirect(string url)
{
  if (Settings.RequestErrors.UseServerSideRedirect)
    HttpContext.Current.Server.Transfer(url);
  else
    WebUtil.Redirect(url, false);
}

. Status System.Web.HttpResponse 404 , . HTTP 404.

- , , URL .

+6

, - .

http://sitecoreblog.tools4geeks.com/Blog/35/Better-way-of-handling-sitecore-404-pages

, , :

  • HttpRequest.ItemResolver HttpRequestBegin.
  • , null, 404.
  • httpRequestEnd EndDiagnostics, 404 .

404 Renderingings. "httpRequestEnd". /404 200 , 200 .

/ .

0

All Articles