문제

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.

도움이 되었습니까?

해결책

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");
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top