Copied to clipboard

Flag this post as spam?

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


  • Paul Griffiths 370 posts 1021 karma points
    Feb 19, 2016 @ 08:54
    Paul Griffiths
    0

    MVC Umbraco 7 Custom 404 Page help

    Hi All,

    I would like to implement a my own custom page not found to present a friendlier error message to the user when they request a page url that does not exist.

    I have done some research and many suggest updating the page ID reference in the <error404>1</error404> tag in the umbracoSetttings.config. Is there a better approach to do this or is this the only way to do it in umbraco?

    In other asp.net mvc applications i have seen it where you can create a controller e.g. pageNotFound controller and in there you just put the follwoing code that simply returns a view

    // GET: PageNotFound
            public ActionResult Index()
            {
                //return 404 view when site page not found
                return View();
            }
    

    In your view (My view is a page that i created in umbaco) you add all your styles to make it look presentable and the final step is to add something like the following in the web.config

    <httpErrors existingResponse="Replace" defaultResponseMode="ExecuteURL" errorMode="Custom">
       <remove statusCode="404" subStatusCode="-1" />
       <error statusCode="404" prefixLanguageFilePath="" path="/PageNotFound" responseMode="ExecuteURL" />
       <remove statusCode="403" subStatusCode="-1" />
       <error statusCode="403" prefixLanguageFilePath="" path="/PageNotFound" responseMode="ExecuteURL" />
    </httpErrors>
    

    View example

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    @{
        Layout = "Layout.cshtml";
    
        //get site root node:
        var siteRoot = CurrentPage.Site();
    }
    
    <div class="container">
        <div class="row">
            <div class="col-md-12 col-sm-12 wow bounceInLeft">
                @{Html.RenderPartial("Breadcrumb");}
                <h3>@Model.Content.GetPropertyValue("pageNotFoundTitle")</h3>
                <img class="img-responsive" src="@Model.Content.GetCropUrl("interestMainImage", "mainImageCrop")" alt="@Model.Content.GetPropertyValue("interestTitle")" title="@Model.Content.GetPropertyValue("interestTitle")" />
                @Model.Content.GetPropertyValue("pageNotFoundContent")
            </div>      
        </div>
    </div>
    

    However, i have tried doing this in my umbraco install and im not really getting anywhere. The furthest i got is my page was rendering but not of the properties were displaying because it appeared to be redirecting to the home page and of course that doesnt have any of my properties as its not the currentPage.

    Im a little confused, so any help or links to documentation to help me implement this functionality will be helpful.

    Many thanks Paul

  • Ismail Mayat 4511 posts 10090 karma points MVP 2x admin c-trib
    Feb 19, 2016 @ 09:13
  • Paul Griffiths 370 posts 1021 karma points
    Feb 19, 2016 @ 09:24
    Paul Griffiths
    0

    Hi Ismail,

    Thanks for the quick response, i will take a look at the links you provided and see whether i can work this one out :)

    Thanks Paul

  • Comment author was deleted

    Feb 19, 2016 @ 09:36

    Hi Paul,

    A super easy way is using this package: https://our.umbraco.org/projects/backoffice-extensions/umbraco-page-not-found-manager/

    Then you have some UI that allows you to pick a 404 page for your site(s)

  • Paul Griffiths 370 posts 1021 karma points
    Feb 19, 2016 @ 09:39
    Paul Griffiths
    0

    Hi Tim,

    Thanks for showing me this package, i will take a look :)

    Many thanks Paul

  • Paul Griffiths 370 posts 1021 karma points
    Feb 20, 2016 @ 08:12
    Paul Griffiths
    0

    Hi lads,

    I decided to following warrens blog post that Ismail provided a link to and I now have the 404 page working 😄.

    The reason I chose that method is I'm trying to get better with programming and although it's only following something at least I'm writing code.

    However, I will try Tim's package as I'm genuinely interested in seeing it.

    Thanks for your input guys, really helpful.

    Paul

Please Sign in or register to post replies

Write your reply to:

Draft