Kentico:如何根据文档类型字段进行重定向

发布于 2024-10-01 17:44:15 字数 263 浏览 0 评论 0原文

我在 Kentico 中有一种特定的文档类型,它有一个布尔字段,当该字段为 true 时,我需要页面重定向到另一个 URL(在本例中为 404 页面)。

执行此操作的最佳地点在哪里?

以及如何在代码中访问 kentico 数据上下文,以便我可以编写提取文档类型字段并基于它进行重定向的代码(因为当前尝试访问 Dataitem("MyFieldName") 错误,因为 Kentico 不使用 DataItem 获取数据绑定,即使 Eval("MyFieldName") 仍然有效。

I have a certain document type in Kentico that has a boolean field that when true i need the page to redirect to another URL (in this case a 404 page).

Where is the best place to do this?

and how do i access the kentico data context in code so that i can write code that pulls the document types field and redirects based on it (because currently trying to access Dataitem("MyFieldName") errors because Kentico doesn't use DataItem for data binding, even though Eval("MyFieldName") still works.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

清浅ˋ旧时光 2024-10-08 17:44:15

您可以通过 CMSContext 对象访问 Kentico 上下文数据。

<%
    if ((bool)CMSContext.CurrentDocument.DataRow["MyFieldName"])
        Response.Redirect("PageNotFound.aspx");
%>

You can access Kentico context data via the CMSContext object.

<%
    if ((bool)CMSContext.CurrentDocument.DataRow["MyFieldName"])
        Response.Redirect("PageNotFound.aspx");
%>
沫雨熙 2024-10-08 17:44:15

如果您只想将一个页面重定向到另一个页面。 Kentico 已经内置了一些东西,只需转到页面 -> 属性 -> 菜单。在菜单操作部分中,您可以指定用于重定向的 URL。

否则,对于所描述的要求,您可以通过以下方式获取布尔值:

if(ValidationHelper.GetBoolean(
    CMSContext.CurrentDocument.GetValue("MyFieldName"), false)))
{
    Response.Redirect("/404.aspx");
}

If you only want to be able to redirect a page to another page. Kentico already have something built in, just go to the Page->Properties->Menu. In the menu actions section you can specify a URL for redirection.

Otherwise for requirement described you can get the boolean value by:

if(ValidationHelper.GetBoolean(
    CMSContext.CurrentDocument.GetValue("MyFieldName"), false)))
{
    Response.Redirect("/404.aspx");
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文