Copied to clipboard

Flag this post as spam?

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


  • Matt 345 posts 807 karma points
    Jan 27, 2023 @ 15:55
    Matt
    0

    Hi all,

    I had a redirect page on umbraco 8 with the following template

    @using Umbraco.Cms.Web.Common.PublishedModels;
    @inherits Umbraco.Cms.Web.Common.Views.UmbracoViewPage<ContentModels.RedirectPage>
    @using ContentModels = Umbraco.Cms.Web.Common.PublishedModels;
    @{
        Layout = "Master.cshtml";
    
            var links = Model.Value<IEnumerable<Link>>("linkTarget");
        if (links != null && links.Any())
        {
            var prettyLink = links.FirstOrDefault();
            Response.RedirectPermanent(prettyLink.Url);
        }
    }
    

    The document type had a URL picker which if you loaded up that page it would redirect you to x page. For some reason this isnt working in Umbraco 10, has something changed?

    Thanks

    Matt

  • Huw Reddick 1185 posts 4042 karma points c-trib
    Jan 27, 2023 @ 16:55
    Huw Reddick
    0

    Hi Matt,

    try adding a return statement after the redirect.

    if (links != null && links.Any())
    {
        var prettyLink = links.FirstOrDefault();
        Response.RedirectPermanent(prettyLink.Url);
        return;
    }
    
  • Matt 345 posts 807 karma points
    Feb 01, 2023 @ 13:47
    Matt
    0

    Thanks for the reply, Unfortnetly still no joy. doesn't redirect :(

  • Matt 345 posts 807 karma points
    Feb 01, 2023 @ 14:01
    Matt
    0

    I get the following

    The name 'Response' does not exist in the current context

  • Huw Reddick 1185 posts 4042 karma points c-trib
    Feb 01, 2023 @ 14:49
    Huw Reddick
    0

    It should be Context.Response

  • Matt 345 posts 807 karma points
    Feb 01, 2023 @ 15:06
    Matt
    0

    Hello Huw

    Thanks for getting back to me, unfortunately I'm getting the following now.

    HttpResponse' does not contain a definition for 'RedirectPermanent' and no accessible extension method 'RedirectPermanent' accepting a first argument of type 'HttpResponse' could be found (are you missing a using directive or an assembly reference?)

    Thanks

  • Huw Reddick 1185 posts 4042 karma points c-trib
    Feb 01, 2023 @ 15:35
    Huw Reddick
    0

    try this

    Context.Response(prettyLink.Url,true);
    
  • Matt 345 posts 807 karma points
    Feb 01, 2023 @ 16:06
    Matt
    0

    Sorry Huw still no joy, I thought it would be simple :(

    Non-invocable member 'HttpContext.Response' cannot be used like a method.

  • Huw Reddick 1185 posts 4042 karma points c-trib
    Feb 01, 2023 @ 16:09
    Huw Reddick
    0

    where exactly are you trying to do this?

    Could you show some more of your code maybe.

  • Matt 345 posts 807 karma points
    Feb 01, 2023 @ 16:12
    Matt
    0

    Hi Huw,

    So I have a doc type in my compositions page called "Redirect Page" inside that I have a url picker.

    Attached to the doc type is a template currently with the following;

    @using Umbraco.Cms.Web.Common.PublishedModels;
    @inherits Umbraco.Cms.Web.Common.Views.UmbracoViewPage<ContentModels.RedirectPage>
    @using ContentModels = Umbraco.Cms.Web.Common.PublishedModels;
    @using Umbraco.Cms.Core.Models;
    @using System;
    
    
    @{
        Layout = "Master.cshtml";
    
            var links = Model.Value<IEnumerable<Link>>("linkTarget");
    if (links != null && links.Any())
    {
        var prettyLink = links.FirstOrDefault();
        Context.Response(prettyLink.Url,true);
        return;
    }
    }
    
  • Huw Reddick 1185 posts 4042 karma points c-trib
    Feb 01, 2023 @ 16:21
    Huw Reddick
    100

    sorry, my typo :)

    Context.Response.Redirect(prettyLink.Url,true);
    
  • Matt 345 posts 807 karma points
    3 days ago
    Matt
    0

    Hi,

    This code works fine but how can I get it to open in a new window?

    @{
        Layout = "Master.cshtml";
    
            var links = Model.Value<IEnumerable<Link>>("linkTarget");
    if (links != null && links.Any())
    {
        var prettyLink = links.FirstOrDefault();
        Context.Response.Redirect(prettyLink.Url,true);
    
    }
    }
    

    Thanks

Please Sign in or register to post replies

Write your reply to:

Draft