Copied to clipboard

Flag this post as spam?

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


  • Alx 1 post 21 karma points
    Aug 12, 2014 @ 20:16
    Alx
    0

    redirect virtual page to external url

    Hello,

    I have been set a challenge.  I need to make "domain.co.uk/thispage" redirect to "domain.co.uk/thispage/thispage.aspx" preferably transparently.

    I have to add a page to the umbraco site that is outside umbraco and will only exist for a short period, but it needs to be on the same domain and look like part of the site.  It will be stored on the same server, in the same site but outside umbraco.

    what is the best way to achieve this? after a while of searching documenation and forums I have seen 

    Umbraco Version: umbraco v 4.7.2 (Assembly version: 1.0.4500.21031)
    IIS Version: 8.5
    asp.net Version: 4.0.30319

    Thanks in advance.

  • Dan Lister 416 posts 1973 karma points c-trib
    Aug 14, 2014 @ 15:06
    Dan Lister
    0

    Hi Alx,

    You could create a new document type called 'Redirect Page' and add a property to it called 'Redirect Url'. Within the new template for the document type, you could perform a redirect to the 'Redirect Url' property value. Something like the following, with a 'Redirect Url' property value of the local page you want to redirect to.

    @inherits UmbracoTemplatePage
    @{
        Layout = null;
    
        var redirectUrl = Model.Content.GetPropertyValue<string>("redirectUrl");
        if (!string.IsNullOrWhiteSpace(redirectUrl))
        {
            Response.Clear();
            Response.StatusCode = 301;
            Response.StatusDescription = "Moved Permanently";
            Response.RedirectLocation = redirectUrl;
            Response.End();
        }
    }
    

    Thanks, Dan.

  • Dan Diplo 1540 posts 6094 karma points MVP 4x c-trib
    Dec 03, 2014 @ 21:16
    Dan Diplo
    0

    Since .NET 4.0 you can just shorten all that code to:

    Response.RedirectPermanent()

    See http://msdn.microsoft.com/en-us/library/system.web.httpresponse.redirectpermanent ;

  • itaRubin 11 posts 110 karma points
    Jan 28, 2021 @ 10:48
    itaRubin
    0

    hi Dan, Response.RedirectPermanent() statusCode is 301.

    if I need Redirect with statusCode = 302?

  • Dan Diplo 1540 posts 6094 karma points MVP 4x c-trib
    Jan 28, 2021 @ 10:52
    Dan Diplo
    1

    You can just use Response.Redirect() which is a 302.

    eg.

    Response.Redirect("http://www.mysite.com/mypage.html");

Please Sign in or register to post replies

Write your reply to:

Draft