5

I have setup DD4T 2 with MVC 5 following the blog - http://blog.building-blocks.com/technical-tips/getting-started-with-dd4t-1-31-asp-net-mvc4-and-sdl-tridion-2013.

Though, I am facing issue while hitting url of my hosted webapp, saying 404 "resource not found". I also checked the related blog, Getting 404 error in DD4T but this is more specific to version 1.31.

I already have a website setup with DD4T 1.31 MVC 4 which works fine . I have compared the configurations of both and everything looks fine.

On further diagnosis, I found that the url is null (which is causing 404) when it hits Page action of PageController, I modified code to manually through the intended page as below -

public override ActionResult Page(string url)
{            
    return base.Page("Dummyview.html");
}

Due to this manual change, 404 error vanished, though I landed in another error while calling RenderComponentPresentations(), below is the complete error with stacktrace -

The controller for path '/dd4t2/' was not found or does not implement IController.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.Web.HttpException: The controller for path '/dd4t2/' was not found or does not implement IController.

Source Error: 


Line 7:  }
Line 8:  This is a page
Line 9:  @Html.RenderComponentPresentations()

Source File: d:\opt\apps\tridion\DD4T2\Views\Page\DummyView.cshtml    Line: 9 

Stack Trace: 


[HttpException (0x80004005): The controller for path '/dd4t2/' was not found or does not implement IController.]
   System.Web.Mvc.DefaultControllerFactory.GetControllerInstance(RequestContext requestContext, Type controllerType) +321
   System.Web.Mvc.DefaultControllerFactory.CreateController(RequestContext requestContext, String controllerName) +169
   System.Web.Mvc.MvcHandler.ProcessRequestInit(HttpContextBase httpContext, IController& controller, IControllerFactory& factory) +270
   System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase httpContext, AsyncCallback callback, Object state) +147
   System.Web.Mvc.ServerExecuteHttpHandlerWrapper.Wrap(Func`1 func) +41

[HttpException (0x80004005): Execution of the child request failed. Please examine the InnerException for more information.]
   System.Web.Mvc.ServerExecuteHttpHandlerWrapper.Wrap(Func`1 func) +178
   System.Web.HttpServerUtility.ExecuteInternal(IHttpHandler handler, TextWriter writer, Boolean preserveForm, Boolean setPreviousPage, VirtualPath path, VirtualPath filePath, String physPath, Exception error, String queryStringOverride) +3977
   System.Web.HttpServerUtility.Execute(IHttpHandler handler, TextWriter writer, Boolean preserveForm, Boolean setPreviousPage) +275
   System.Web.HttpServerUtilityWrapper.Execute(IHttpHandler handler, TextWriter writer, Boolean preserveForm) +94
   System.Web.Mvc.Html.ChildActionExtensions.ActionHelper(HtmlHelper htmlHelper, String actionName, String controllerName, RouteValueDictionary routeValues, TextWriter textWriter) +716
   System.Web.Mvc.Html.ChildActionExtensions.Action(HtmlHelper htmlHelper, String actionName, String controllerName, RouteValueDictionary routeValues) +123
   DD4T.Mvc.Html.DefaultComponentPresentationRenderer.RenderComponentPresentation(IComponentPresentation cp, HtmlHelper htmlHelper) +684
   DD4T.Mvc.Html.DefaultComponentPresentationRenderer.ComponentPresentations(IPage tridionPage, HtmlHelper htmlHelper, String[] includeComponentTemplate, String includeSchema) +924
   DD4T.Mvc.Html.TridionHelper.RenderComponentPresentations(HtmlHelper helper, String[] byComponentTemplate, String bySchema, IComponentPresentationRenderer renderer) +1000
   ASP._Page_Views_Page_DummyView_cshtml.Execute() in d:\opt\apps\tridion\DD4T2\Views\Page\DummyView.cshtml:9
   System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +280
   System.Web.Mvc.WebViewPage.ExecutePageHierarchy() +126
   System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +110
   System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) +380
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +109
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +890
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult) +97
   System.Web.Mvc.Async.c__DisplayClass21.b__1e(IAsyncResult asyncResult) +241
   System.Web.Mvc.Controller.b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState) +29
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +111
   System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +53
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +19
   System.Web.Mvc.MvcHandler.b__5(IAsyncResult asyncResult, ProcessRequestState innerState) +51
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +111
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +606
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +288

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.34280
2

The issue got resolved. The code solution was missing ComponentController. I just added a ComponentController with a constructor like following and it worked -

public class ComponentController : TridionControllerBase
{
    public ComponentController(IPageFactory pageFactory, IComponentPresentationFactory componentPresentationFactory, ILogger logger, IDD4TConfiguration configuration) :
        base(pageFactory, componentPresentationFactory, logger, configuration)
    {

    }
}
1

With DD4T 2.0, there is a better and suggested approach to render the component presentation with view models.

http://blog.building-blocks.com/technical-tips/getting-started-with-dd4t-1-31-asp-net-mvc4-and-sdl-tridion-2013

This approach, your render presentation would look like..

  @foreach (var item in Model.Items)
  {
       @Html.Render(item)
  }

I believe in your case, Please confirm if your ComponentController is implemented from TridionControllerBase

0

A 404 error may indicate some of the following:

  • the filename extension of your URL is not routed to be executed in IIS. For example some static extension like *.html is not going to trigger code execution. You'll need to add a handler in your web.config:

    <add name="HtmlFileHandler" path="*.html"
        verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS"
        type="System.Web.Handlers.TransferRequestHandler"
        preCondition="integratedMode,runtimeVersionv4.0" />
    
  • the route is not configured correctly. Check with a simpler or default route to see if your controller gets hit. Put a breakpoint or some logging in the controller to see if it executes:

        routes.MapRoute(
            name: "TridionPage",
            url: "{*pageUrl}",
            defaults: new { controller = "Page", action = "Page" }
        );
    
  • the page is not published. The controller attempts to read the page by URL, but it fails to do so and it yields a 404. Try debug your controller or put some logging statements in it.

  • Thanks for the help, I checked all above points and they seem to be fine here, Page is published. I have edited my question with more information. Please have a look. – Stark Apr 5 '16 at 6:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.