January 15, 2011

Re-add Redirects to Sitefinity 4.0

If you are trying to use Sitefinity 4.0 and are missing the ability to add external URL's like you could in Sitefinity 3.7, here is a partial solution.

RedirectToUrl.ascx:
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="RedirectToUrl.ascx.cs" Inherits="SitefinityWebApp.UserControls.RedirectToUrl" EnableViewState="false" %>


RedirectToUrl.ascx.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Sitefinity.Web.UI;

namespace SitefinityWebApp.UserControls
{
public partial class RedirectToUrl : System.Web.UI.UserControl
{
public string DestinationUrl { get; set; }

public bool PermanentRedirect { get; set; }

protected void Page_Load(object sender, EventArgs e)
{
bool inDesignMode = this.IsDesignMode();
if (!String.IsNullOrWhiteSpace(DestinationUrl))
{
if (inDesignMode)
{
Output.Text = Server.HtmlEncode("Redirect to " + DestinationUrl);
}
else
{
if (PermanentRedirect)
{
Response.RedirectPermanent(DestinationUrl, false);
}
else
{
Response.Redirect(DestinationUrl, false);
}
}
}
else
{
if (inDesignMode)
{
Output.Text = "Warning: No redirect URL found";
}
else
{
Output.Text = "";
}
}
}
}
}

No comments: