获取推荐项目(链接)
我们有一个 Sitecore 网站,我们需要知道将您带到第 X 页的链接的项目。 示例:
您在页面 A 上并单击项目 X 提供的链接,该链接会将您引导至页面 B。
在页面 B 上,我们需要能够获取 X 向您推荐的项目,从而访问该项目及其属性。
它可以通过会话、Sitecore 上下文,我不知道是什么,我们甚至不需要整个项目本身,只需要 ID 即可。
有人知道如何做到这一点吗?
We have a sitecore website and we need to know the item from which the link that brought you to page X.
Example:
You're on page A and click a link provided by item X that will lead you to page B.
On page B we need to be able to get that item X referred you, and thus access the item and it's properties.
It could go through session, Sitecore context, I don't know what and we don't even need the entire item itself, just the ID would do.
Anyone know how to accomplish this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
从评论中的讨论来看,您遇到了一个并非特定于 Sitecore 的 Web 架构问题。
您有一个后端,它使用多个数据项来生成一些发送到客户端的 HTML。这些数据项中的每一个都可以在 HTML 中生成链接。它们可能会产生相同的链接。只有其中一项被视为 HTML 页面的源。
您不想知道哪些项目产生了链接。您唯一的选择是找到一种识别所生成链接的方法。为此,您必须向生成的 URL 添加某种形式的标记信息(例如查询字符串),以便在处理 URL 请求时对其进行解释。这些项目本身并不存在于客户端中。
如果您的链接是由数据库查询生成的,问题将完全相同。如果您想知道哪个记录生成了链接,则必须向链接添加标识符。
您可能会设计一个系统,允许您在大多数时间识别项目(即,当单击的链接对于该页面是唯一的时),但它会涉及在会话中缓存大量数据(生成的链接列表以及生成这些链接的项目)或重新创建引用 URL 的请求。对于一个不完美的解决方案来说,这两种听起来都是很麻烦的,而且可能会大大降低服务器的速度。
From the discussion in the comments you have a web-architecture problem that isn't really Sitecore specific.
You have a back end which consumes several data items to produce some HTML which is sent to the client. Each of those data items may produce links in the HTML. They may produce identical links. Only one of the items is considered the source of the HTML page.
You wan't to know which of those items produced the link. Your only option is to find a way of identifying the links produced. To do this you will have to add some form of tagging information to the URL produced(such as a querystring) that can be interpretted when the request for the URL is processed. The items themselves don't exist in the client.
The problem would be exactly the same if your links were produced by a database query. If you wanted to know which record produced the link you'd have to add an identifier to the link.
You could probably devise a system that would allow you to identify item most of the time (i.e. when the link clicked on was unique to that page), but it would involve either caching lots of data in a session (list of links produced and the items that produced them) or recreating the request for the referring URL. Either sounds like a lot of hassle for a non-perfect solution that could feasibly slow your server down a fair amount.
詹姆斯是对的……你原来的参数基本上是不可能满足的。
不过,通过对标准 Sitecore 提供商进行一些黑客攻击和替换,您可以跟踪这些内容。但使用某种查询字符串 ID 会容易得多。
在我们的系统上,我们有第 3 方广告链接...他们有客户端 javascript,它实际上将请求提交到本地页面,然后重定向到目标 URL。因此,当您将鼠标悬停在链接上时,状态栏会显示“http://whatever.com”...它似乎链接将指向whatever.com,但实际上您将< a href="http://ourserver/redirect.aspx" rel="nofollow">http://ourserver/redirect.aspx 首先,这样我们就可以跟踪该链接,然后获取 Response.Redirect() 。
您可以通过提供自己的 LinkManager 并在跟踪 URL 中包含生成的项目 ID,然后重定向到用户想要的实际页面/项目来执行类似的操作。
然而......这看起来相当复杂且容易出错,我不会推荐它。
James is correct... your original parameters are basically impossible to satisfy.
With some hacking and replacing of the standard Sitecore providers though, you could track these. But it would be far easier to use a querystring ID of some sort.
On our system, we have 3rd party advertising links... they have client javascript which actually submits the request to a local page and then gets redirected to the target URL. So when you hover over the link, the status bar shows you "http://whatever.com"... it appears the link is going to whatever.com, but you are actually going to http://ourserver/redirect.aspx first so we can track that link, and then getting a Response.Redirect().
You could do something similar by providing your own LinkManager and including the generating item ID in the tracking URL, then redirecting to the actual page/item the user wants.
However... this seems rather convoluted and error-prone, and I would not recommend it.