sách gpt4 ai đã đi

sitecore - 获取与 Sitecore 中的 URL 匹配的项目

In lại 作者:行者123 更新时间:2023-12-04 17:23:58 hai mươi bốn 4
mua khóa gpt4 Nike

在我正在构建的站点中,我尝试使用引用来验证 AJAX 请求是否来自正确的 URL。

为此,我想让 Sitecore 解析一个项目的 URL。例如,
http://www.mysite.com/abc/def
可能会解析到路径中的项目
sitecore/Content/MySite/Home/abc/def
在我的代码中推荐的方法是什么?

1 Câu trả lời

感谢所有的答案,但他们都没有做我需要的一切。这对我有用。

var url = new Uri(...);

// Obtain a SiteContext for the host and virtual path
var siteContext = SiteContextFactory.GetSiteContext(url.Host, url.PathAndQuery);

// Get the path to the Home item
var homePath = siteContext.StartPath;
if (!homePath.EndsWith("/"))
homePath += "/";

// Get the path to the item, removing virtual path if any
var itemPath = MainUtil.DecodeName(url.AbsolutePath);
if (itemPath.StartsWith(siteContext.VirtualFolder))
itemPath = itemPath.Remove(0,siteContext.VirtualFolder.Length);

// Obtain the item
var fullPath = homePath + itemPath;
var item = siteContext.Database.GetItem(fullPath);

关于sitecore - 获取与 Sitecore 中的 URL 匹配的项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13814955/

hai mươi bốn 4 0
行者123
Hồ sơ cá nhân

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá Didi Taxi miễn phí
Mã giảm giá Didi Taxi
Giấy chứng nhận ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com