Umbraco .NET C# Usercontrol Permenant Redirect to Parent Node

This is the Code behind file to permanantly redirect to a parent node in Umbraco.
There is no need to have any controls on the .asxp page.


Step 1: Create a .Net User Control called: "RedirectToPARENTnode.aspx"

Step 2: Paste the code in to the code behind file (.cs):

(important bits highlighted in yellow)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using umbraco;
using umbraco.presentation.nodeFactory;

namespace MyUserControls.Usercontrols
{
    public partial class RedirectToPARENTnode : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {  
            //MD 06/08/2012
           
           //get the current node
            Node currentPage = Node.GetCurrent();


          
           //get the parent node
            Node parentPage = currentPage.Parent;

           
            //redirect to parent node
            Response.RedirectPermanent(parentPage.Url);

        }
    }
}

Comments

Popular posts from this blog

Umbraco - Reset the Admin Password via SQL Server

Create a .NET Contact Form that Gets the Last Url Visited in C# Can also be Used in Umbraco

Umbraco Macro for IFrame when Embedding Video, Vimeo Universal Player, or other types of IFrame on to a Page XSLT version and Razor Version