Copied to clipboard

Flag this post as spam?

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


  • atze187 160 posts 215 karma points
    Nov 27, 2009 @ 10:58
    atze187
    0

    How to raise umbraco 404 error in IIS

    Hi,

    i have started a topic on this a while ago, but the suggested solution is a pain:

    I want to deal with only one 404 handler and preferably this is the one configured within the IIS, since i want to handle error outside of umbraco as well (e.g. for classic .asp pages or download files, which are not handled by umbraco). I came to the conclusion that my target of customization would be the umbraco requestHandler, but i have no clue how to raise an IIS 404 error from there if currentPage is null. Any ideas?

    Thanks,
    André

  • Chris Koiak 700 posts 2626 karma points
    Nov 27, 2009 @ 14:18
    Chris Koiak
    0

    I would suggest you make a plain staic 404 handler for non aspx pages. To handle this in a requestHandler you need to route all requests through .NET.

  • atze187 160 posts 215 karma points
    Nov 27, 2009 @ 14:58
    atze187
    0

    Hi Chris,

    I have found a working solution, which requires the umbraco requestHandler to be modified and raises a IIS error, so i can handle all errors using one single error page. I will post my solution tonight, as i have to get my daughter from daycare now.

    Cheers,
    André

  • atze187 160 posts 215 karma points
    Nov 30, 2009 @ 14:07
    atze187
    1

    So, a little late, but here is my - simplified (using a custom asp.net error page) - solution for 4.0.21:

    requestHandler.cs

    In requestHandler.cs (part of the source distribution and located in the umbraco.presentation project) you have to comment out the content (and only the content, not the if-statement itself) of the following if-statement appearing in the constructor:

    if (currentPage == null) 

    and put something like this into this if statement:

    HttpException ex;
    ex = new HttpException(404, "Requested document was not found");
    throw ex;

    This raises a HttpExcepton with 404 error code that will be handled by IIS configured error management.

    web.config

    Of course you have to set up the by modifying the "customErrors" element of your web.config like this:

    <customErrors mode="On" redirectMode="ResponseRewrite" defaultRedirect="~/ErrorPages/PageNotFound.aspx" />

    and add the errorpage's virtual path to the "umbracoReservedUrls" appSettings element, so umbraco won't try to handle your errorpage.

    Your error page

    Your error page holds all your your logic to set the appropriate error codes and redirection targets. Basically it may looks like this:

    protected void Page_Load(object sender, EventArgs e)
    {
        if (Context.Error != null)
        {
            Response.StatusCode = your_specific_error_code;
            Response.RedirectLocation = your_specific_redirection_target;
        }
    }

    So, that's it.

Please Sign in or register to post replies

Write your reply to:

Draft