Umbraco - C# - Redirect a Umbraco Page to an external web site.
Umbraco - C# - How to Redirect a Umbraco Page to an external web site.
Two create a redirect from a Umbraco page to an exteral site you need to: (this is very simple)Step 1) Add the page to Umbraco that you want to rediect. (You may want to Hide this page from navigation)
Step 2) Create a new Web Form in C# Visual Studio
(this web form will be placed in the route of the site)
Step 3) Update the Web Config to include the new file mentioned in step 2
(or you will get a Server error in appliaction)
Step 4) Add a Url redirect to the UrlRewriting.config, from the Umbraco page (created in step 1), to the web form (created in step 2).
Step 2: Here is the C# Code (my-redirect-example.aspx) form for step 2:
(it is basically a blank form)<%@ Page Language="C#" AutoEventWireup="true" CodeFile="my-redirect-example.aspx.cs" Inherits="my_redirect_example" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body onload="open_on_entrance()">
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>
Here is the C# Code (my-redirect-example.aspx.cs) form for step 2:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class my_redirect_example : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Response.Redirect("http://www.markdownie.me.uk");
}
}
Step 3: Here is the line you need to add to the Web Config file for step 3:
Add this in your <appSettings> section.
<add key="umbracoReservedUrls" value="~/my-redirect-example.aspx" />
Step 4: Here is the Code you need to add to the UrlRewriting.config file:
<add
name="myExternalRedirect"
virtualUrl="^~/my-page.aspx"
destinationUrl="~/my-redirect-example.aspx"
ignoreCase="true"
redirect="Application"
redirectMode="Permanent"/>
Note: Highlighted Yellow, ^~/my-page.asp . This is the name of the Umbraco Page you create in Step 1.
If you experience any issues with this code, please let me know....
This comment has been removed by the author.
ReplyDelete