English 中文(简体)
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 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");
}




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签