Copied to clipboard

Flag this post as spam?

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


  • Lee 1130 posts 3088 karma points
    Feb 04, 2013 @ 10:02
    Lee
    0

    INotFoundHandler To Custom Url?

    Is it possible to create a class that implements 'INotFoundHandler' but instead of redirecting by passing in a nodeid. Redirect to a url I specify? like /my-domain/my-re-written-page-name ??

  • Richard Soeteman 4051 posts 12924 karma points MVP 2x
    Feb 04, 2013 @ 10:09
    Richard Soeteman
    1

    Think you can set the response code to 301. Try the SetResponse method below.

    SetResponse("/re-written-page-name",301,"Moved permanently");
     
    private void SetResponse(string url, int statusCode, string statusDescription)
    {
    _redirectId = documentId == 0 ? -1 : documentId;
    HttpContext.Current.Response.StatusCode = statusCode;
    HttpContext.Current.Response.Status = statusDescription;
    HttpContext.Current.Response.AddHeader("Location", url);
    }

    Hope this helps,

    Richard

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Feb 04, 2013 @ 10:13
    Dirk De Grave
    100

    i'm using a redirectpermanent(newurl) in the execute method of the not found handler which works as expected and sets the codes and location for you.

     

    /Dirk

  • Lee 1130 posts 3088 karma points
    Feb 04, 2013 @ 10:27
    Lee
    0

    Ahh. So you 'could' simply response.redirect (Or 301 redirect) from within the execute method and it would work correctly and correct header status code gets set?

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Feb 04, 2013 @ 10:30
    Dirk De Grave
    1

    Yup, PermantRedirect does all the stuff for you, just need to provide the new url to redirect to.

     

    /Dirk

  • Richard Soeteman 4051 posts 12924 karma points MVP 2x
    Feb 04, 2013 @ 10:32
    Richard Soeteman
    1

    Yup and Dirk's comment is better. I used the old one since it came from a .net 2.0 project...

  • Lee 1130 posts 3088 karma points
    Feb 04, 2013 @ 10:33
    Lee
    0

    Where is this permanantRedirect method? I can't find it in umbraco.library?

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Feb 04, 2013 @ 10:34
    Dirk De Grave
    1

    HttpContext.Current.Response object

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Feb 04, 2013 @ 10:35
    Dirk De Grave
    1

    Oops, it's RedirectPermanent instead of PermanentRedirect

  • Lee 1130 posts 3088 karma points
    Feb 04, 2013 @ 10:38
    Lee
    0

    Thanks chaps :)

Please Sign in or register to post replies

Write your reply to:

Draft