Copied to clipboard

Flag this post as spam?

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


  • Chris Koiak 700 posts 2626 karma points
    Nov 29, 2010 @ 11:36
    Chris Koiak
    1

    4.5 Compatibility

    I just installed this great package on a 4.5 site, without realising it didn't support version 4.5. I just tweaked the code slightly to support 4.5, and thought I'd share it.

    Here the code for the main redirect class

     private bool m_cacheUrl;
    private int m_redirectId;


    public bool CacheUrl
    {
    get
    {
    return this.m_cacheUrl;
    }
    }


    public int redirectID
    {
    get
    {
    return this.m_redirectId;
    }
    }

    public Redirect301Handler()
    {
    this.m_cacheUrl = true;
    this.m_redirectId = -1;
    }


    public bool Execute(string url)
    {
    string str = url;
    if (str.Length > 0)
    {
    if (str.Substring(0, 1) == "/")
    {
    str = str.Substring(1, str.Length - 1);
    }
    HttpContext.Current.Trace.Write("umbraco301MovedPermanently", "'" + str + "'");
    string domainName = HttpContext.Current.Request.ServerVariables["SERVER_NAME"];
    string str3 = string.Empty;
    if (Domain.Exists(domainName))
    {
    str3 = "//*[@id='" + Domain.GetRootFromDomain(domainName) + "']";
    this.m_cacheUrl = false;
    }
    string xpath = string.Format("{0}//*[contains(concat(',', umbraco301MovedPermanently, ','), ',{1},')]", str3, str.Replace(".aspx", string.Empty).ToLower());
    XmlNode node = umbraco.content.Instance.XmlContent.DocumentElement.SelectSingleNode(xpath);
    if ((node != null) && int.TryParse(node.Attributes.GetNamedItem("id").Value, out this.m_redirectId))
    {
    string str5 = umbraco.library.NiceUrl(this.m_redirectId);
    this.m_cacheUrl = true;
    HttpContext.Current.Response.Clear();
    HttpContext.Current.Response.StatusCode = 0x12d;
    HttpContext.Current.Response.Status = "301 Moved Permanently";
    HttpContext.Current.Response.AddHeader("Location", str5);
    HttpContext.Current.Response.End();
    return true;
    }
    }
    return false;
    }

     

  • Lee Kelleher 4020 posts 15802 karma points MVP 13x admin c-trib
    Nov 29, 2010 @ 12:30
    Lee Kelleher
    1

    Hi Chris,

    Thanks for the updated code, much appreciated! Glad you got it working.

    I did actually update the code for v4.5 - which its now going to be part of uComponents (in the v2 release).  I will get around to releasing it as a standalone package too, as uComponents might seem a little overkill if you only need a small part of it!

    Cheers, Lee.

  • Chris Koiak 700 posts 2626 karma points
    Nov 29, 2010 @ 12:35
    Chris Koiak
    0

    Cool, I didn't know it was moving into uComponents, that's great news.

    I now install uComponets with every new site build, this is a great addition to it.

    Cheers, Chris

  • Lee Kelleher 4020 posts 15802 karma points MVP 13x admin c-trib
    Nov 29, 2010 @ 12:38
    Lee Kelleher
    0

    We're aiming for a v2 release of uComponents early next week.  My thinking was that a lot of people are using uComponents as a "must have" package, so seemed a good idea to include some of the smaller classes/components in there too.

    Still I will release this 301 package as a standalone too ... just need to keep the codebases in sync! ;-)

    Cheers, Lee.

Please Sign in or register to post replies

Write your reply to:

Draft