Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open PageNotFoundContentFinder logic for other scenarios? #6

Open
nvisage-gf opened this issue Nov 11, 2015 · 0 comments
Open

Open PageNotFoundContentFinder logic for other scenarios? #6

nvisage-gf opened this issue Nov 11, 2015 · 0 comments

Comments

@nvisage-gf
Copy link

Would it be possible to make the content finder logic available publicly (extension methods maybe) to enable using from a controller (for example). We have a multi site install using Hybrid Framework route hijacking and virtual nodes with some content retrieved from external web services; we'd like to catch 404 WebExceptions returned from web service calls or HttpExceptions thrown by our controller logic in the base/abstract SurfaceController similar to this:

    protected override void OnException(ExceptionContext filterContext)
    {
        // Bail if we can't do anything; app will crash.
        if (filterContext == null)
        {
            return;
        }

        if (filterContext.ExceptionHandled)
        {
            return;
        }

        var ex = filterContext.Exception ?? new ApplicationException("No further information exists.");

        if (ex.IsNotFound())   // IsNotFound checks WebException or HttpException for 404 status
        {
            // handle this as a 404 using closest not found page for request
            var notFoundPage = PageNotFoundContentFinder.NotFoundPage(UmbracoContext.Current.PublishedContentRequest);
            var model = ModelLogic.CreateMasterModel(notFoundPage) as MasterModel<NotFound>;
            filterContext.Result = View("NotFound", model);
            filterContext.HttpContext.Response.StatusCode = (int) HttpStatusCode.NotFound;
            filterContext.ExceptionHandled = true;
        }
        else
        {
            // Log the exception.
        }
    }

We have this working using modified code for review/comment (probably should use helper / extension methods)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant