Kentico 12 MVC - The resource cannot be found message on page preview

Petline developer asked on May 2, 2019 22:53

I work on Kentico 12 MVC, and wanted to know something basic regarding URL pattern for previewing content only pages. I able to see the home page, but once I added another new content-only page type , and trying to preview that page I get "The resource cannot be found." message.

Under the " Page types> General > URL pattern" I tried "/{%NodeAlias%}" and "/blog" but none is working and I keep getting the above message when I preview or when I use the "Page" tab.

can someone please help, I am sure I am missing something really simple.

Thanks!

Correct Answer

David te Kloese answered on May 6, 2019 11:03

Well in your controller you currently have:

public ActionResult Index()
{
        OurBlog page = OurBlogProvider.GetOurBlog("/blog", "en-us", "KenticoTest");            
        ...
} 

Which isn't dynamic at all...

You could change it to something like:

public ActionResult Index(int nodeId, string nodeAliasPath)
{
        OurBlog page = OurBlogProvider.GetOurBlog(nodeId,
            LocalizationContext.CurrentCulture.CultureCode,
            SiteContext.CurrentSiteName);
            // extend this with more properties like columns, only published, etc.

        ...
} 

This will try to retrieve the pages based on the NodeID.

0 votesVote for this answer Unmark Correct answer

Recent Answers


David te Kloese answered on May 3, 2019 10:02 (last edited on May 3, 2019 10:04)

How MVC works is that you have registered Routes...

You have to make sure that the URL pattern you enter has a valid route that points to a controller that knows how to handle that url.

So first check the RouteConfig.cs probably in your App_start folder.

Say you have a news page. You could setup a route like (note that i simplified it):

        route = routes.MapRoute(
          name: "news",
          url: "news/{nodeId}/{nodeName}",
          defaults: new { controller = "News", action = "Detail", nodeName = UrlParameter.Optional }
          );

In the News Controller your Detailed action method can retrieve the page based on type (news) and nodeID which is in the URL.

    public ActionResult Detail(int nodeId, string nodeName)
    {
        /// ... some logic retrieving the model based on NodeID
        return View("NewsDetail", model);
    }

at this point you can setup your UrlPattern to be "news/{%NodeID%}/{%NodeAlias%}

0 votesVote for this answer Mark as a Correct answer

Petline developer answered on May 3, 2019 15:08

Hi David,

Thanks so much for getting back to me, so under the RouteConfig.cs file I have this:

Code
            routes.MapRoute(
            name: "OurBlog",
            url: "{controller}/{action}/{id}",
            defaults: new { controller = "OurBlog", action = "Index", id = UrlParameter.Optional }
        );

And under the "OurBlogController" I have this:

Code
    public ActionResult Index()
    {
        OurBlog page = OurBlogProvider.GetOurBlog("/blog", "en-us", "KenticoTest");

        // Returns a 404 error when the retrieving is unsuccessful
        if (page == null)
        {
            return HttpNotFound();
        }

        // Initializes the page builder with the DocumentID of the page
        HttpContext.Kentico().PageBuilder().Initialize(page.DocumentID);

        return View(page);
    }

I did try what you suggested, but right now I have only one simple page, no sub pages. I still get the error. can you please advise what else I might be missing??

Thanks!

0 votesVote for this answer Mark as a Correct answer

David te Kloese answered on May 3, 2019 16:36

Yes but you don't use the ID parameter. So your query

OurBlogProvider.GetOurBlog("/blog", "en-us", "KenticoTest");

Will always return the same result. You should update it to use that property NodeID in it's dataretrieval.

0 votesVote for this answer Mark as a Correct answer

Petline developer answered on May 3, 2019 16:54

sorry, not sure I understand, can you please specify what line I need to updated? Is the below line, is the only issue? OurBlogProvider.GetOurBlog("/blog", "en-us", "KenticoTest");

Or if you can provide an example based on what I am using.

thanks

0 votesVote for this answer Mark as a Correct answer

Petline developer answered on May 3, 2019 22:01

Can someone please reply back, i am still stuck with that error message

0 votesVote for this answer Mark as a Correct answer

Petline developer answered on May 6, 2019 15:11

Thanks so much!! that did the work

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.