Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6723281
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:33:02+00:00 2026-05-26T09:33:02+00:00

I am setting up a page and sub-page system for a site. So, let’s

  • 0

I am setting up a page and sub-page system for a site. So, let’s say there is an “Index” page, with a “Sub” page. To access the sub page the URL would look like this: “Index/Sub”.

There could another page with “Sub” for the URL part. IE: “Index/Sub” and “AnotherPage/Sub”.
In ASP.NET MVC, I am taking a URL and splitting it into an array on forward slashes. Then I use EF4.1 to find the correct page entity.

As I look at the code, it works, but I’m wondering if I can reduce the number of calls to the database. Here’s my test action:

    public string Index(string url)
    {
        // split url into array
        string[] slugs = url.Split('/');
        string currentSlug = slugs[0];

        // set starting page and loop
        Page page = db.Pages.FirstOrDefault(x => x.Slug == currentSlug);
        for (var i = 1; i < slugs.Count(); i++)
        {
            if (!string.IsNullOrEmpty(slugs[i]) 
                && page != null 
                && page.Children != null)
            {
                page = page.Children.FirstOrDefault(x => x.Slug == slugs[i]);
            }
        }

        // if null return 404
        if(page == null) throw new HttpException(404, "HTTP/1.1 404 Not Found");

        // return page
        return page.Label;
    }

Is this scary or alright? Is there a way to reduce the potential number of db calls?

-Thanks for any tips-

Edit

Here’s my Page model FYI

public class Page
{
    public Guid PageId { get; set; }

    [Required(ErrorMessage = "URL is required")]
    [StringLength(30, ErrorMessage = "Must be less than 30 characters")]
    public string Slug { get; set; }

    [Required(ErrorMessage = "Label is required")]
    [StringLength(30, ErrorMessage = "Must be less than 30 characters")]
    public string Label { get; set; }

    [StringLength(100, ErrorMessage = "Must be less than 100 characters")]
    public string Title { get; set; }

    [StringLength(255, ErrorMessage = "Must be less than 255 characters")]
    public string Keywords { get; set; }

    [StringLength(300, ErrorMessage = "Must be less than 300 characters")]
    public string Description { get; set; }

    public DateTime DateCreated { get; set; }

    public DateTime DateModified { get; set; }

    public string LayoutName { get; set; }

    public virtual ICollection<Content> Contents { get; set; }

    public virtual Page Parent { get; set; }

    public virtual ICollection<Page> Children { get; set; }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T09:33:02+00:00Added an answer on May 26, 2026 at 9:33 am

    I’d certainly include the full page path on each Page, so you can do the query in one db call. (Yes, then the data will not be fully normalised in the DB, but that a sacrifice we sometimes have to make for the sake of performance). Just make sure you have a strategy to update sub pages when ever a parent page changes.

    If you dislike the idea of a full path column on the pages, perhaps you should cache the paths and the page ID’s they resolve to, instead of asking the DB each time (Remember to have a cache clearing strategy).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm setting up a very straightforward FAQ page with jQuery. Like so: <h2>What happens
Supposing I'm setting a background image for a web page in CSS like this:
Imports System.Net.Mail Partial Class ContactUs Inherits System.Web.UI.Page Protected Sub LinkButton1_Click(ByVal sender As Object, ByVal
hi here is my live page http://mehrdadkhoshbakht.com/test/index.html there is a jquery sliding animation on
Imports System Imports System.IO Imports System.Linq Namespace PhotoGalleryApp Partial Public Class Index Inherits System.Web.UI.Page
I have a use case where I am setting the page focus to a
If i have a HTML page with setting to be UTF-8. and then I
My wordpress is not setting the front page correctly, I have several pages, all
I'm embedding a flash swf into an html page and setting wmode=transparent. I need
How to view all the content in my IsolatedStorageFile by setting a new page

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.