开发者

Kentico: How to redirect based on document type field

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 D开发者_Python百科ataItem for data binding, even though Eval("MyFieldName") still works.


You can access Kentico context data via the CMSContext object.

<%
    if ((bool)CMSContext.CurrentDocument.DataRow["MyFieldName"])
        Response.Redirect("PageNotFound.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");
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜