I'm building a website where most of the pages can be modified by querystring parameter. For example if a parameter "member" is passed in the header renders a different logo. From that moment on all links should use it for further use. As I generally use the IPublishedContent.Url property to link to other pages it is probably the best solution to modify the URL property by just adding ?member=xxx to the URL globally. Is there any way to achieve this?
You could achieve this with an extension method on IPublishedContent:
public static class PublishedContentExtensions
{
public static string MyUrl(this IPublishedContent content)
{
var member = HttpContext.Current.Request.QueryString["member"];
if (string.IsNullOrEmpty(member))
{
return content.Url;
}
return content.Url + "?member=" + member;
}
}
Put this class somewhere in your project and then in your views you'll be able to do something like this:
Override IpublishedContent.Url
Hi!
I'm building a website where most of the pages can be modified by querystring parameter. For example if a parameter "member" is passed in the header renders a different logo. From that moment on all links should use it for further use. As I generally use the IPublishedContent.Url property to link to other pages it is probably the best solution to modify the URL property by just adding ?member=xxx to the URL globally. Is there any way to achieve this?
Create 2 Extension classes, 1 for Umbracohelper (if you use it) and 1 for IPublishedContent and 1 helper class for the shared logic.
And then use one of these 2 calls in your views(you will most likely use the second one)
If anyone can give me a workaround on how to get the Request without passing it, I would be gratefull.
Hi Sven,
See my example. The idea is pretty much the same. You can get the current request using
HttpContext.Current.Request
.You mean something like this?
https://creativewebspecialist.co.uk/2013/12/03/using-umbraco-pipeline-for-member-profile-urls/
Hi Patric,
You could achieve this with an extension method on
IPublishedContent
:Put this class somewhere in your project and then in your views you'll be able to do something like this:
Thanks a lot, that was exactly what I was looking for!
is working on a reply...