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 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?)
This code works fine but how can I get it to open in a new window?
Its been a while so you probably figured this out, but - you cant.
By using Response.Redirect what you are doing is telling the server to send a 302 status back to the client with the location header set to a URL, that in turn tells the browser that it should do another GET request to the new URL.
If you want to open a new window, that would have to be handled client side and you wouldn't be able to do it with a redirect which originated on the server (Unless you do some weird stuff to intercept the response, stop the browser redirecting and then open the new windows... I would not recommend attempting that).
If I had this requirement I'd probably be looking to do it with client side JavaScript rather than having the roundtrip back to the server if you KNOW that its just going to result in another GET request anyway.
Redirect Template page
Hi all,
I had a redirect page on umbraco 8 with the following template
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
Hi Matt,
try adding a return statement after the redirect.
Thanks for the reply, Unfortnetly still no joy. doesn't redirect :(
I get the following
The name 'Response' does not exist in the current context
It should be Context.Response
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
try this
Sorry Huw still no joy, I thought it would be simple :(
Non-invocable member 'HttpContext.Response' cannot be used like a method.
where exactly are you trying to do this?
Could you show some more of your code maybe.
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;
sorry, my typo :)
Hi,
This code works fine but how can I get it to open in a new window?
Thanks
Its been a while so you probably figured this out, but - you cant.
By using
Response.Redirect
what you are doing is telling the server to send a 302 status back to the client with the location header set to a URL, that in turn tells the browser that it should do anotherGET
request to the new URL.If you want to open a new window, that would have to be handled client side and you wouldn't be able to do it with a redirect which originated on the server (Unless you do some weird stuff to intercept the response, stop the browser redirecting and then open the new windows... I would not recommend attempting that).
If I had this requirement I'd probably be looking to do it with client side JavaScript rather than having the roundtrip back to the server if you KNOW that its just going to result in another GET request anyway.
is working on a reply...