Suppressing Navigation Rendering Per Request

cloudscribe.Web.Navigation supports suppressing the rendering of navigation view components on a per-request basis. This is useful when certain pages don't need the navigation tree at all — for example, login or registration pages, landing pages, or any page where computing and rendering the menu is unnecessary overhead.

How It Works

The suppression mechanism uses HttpContext.Items to pass a flag from your controller action to the navigation view components. You set the flag early in the request; when the view component executes during layout rendering, it checks for the flag and returns empty content instead of building the navigation tree.

Because the check happens inside the view components themselves, no changes to _Layout.cshtml are required. The @await Component.InvokeAsync calls remain in the layout as normal — they simply produce no output when suppressed.

NavigationSuppressor

The NavigationSuppressor static class provides two methods:

// Mark a named navigation filter as suppressed for this request
NavigationSuppressor.SuppressFilter(HttpContext, "TopNav");
NavigationSuppressor.SuppressFilter(HttpContext, "Breadcrumbs");

// Check whether a filter is suppressed (used internally by the view components)
bool suppressed = NavigationSuppressor.IsFilterSuppressed(HttpContext, "TopNav");

The filter name you pass here corresponds to the filterName parameter on the navigation view component. You can suppress any named filter, and multiple filters can be suppressed independently on the same request. The well-known filter names are available as constants on NamedNavigationFilters.

Both NavigationViewComponent and CachingNavigationViewComponent check the suppression flag before doing any work. If the filter is suppressed, the component returns empty content immediately — no tree building, no database queries, no cache lookups.

Usage

Call NavigationSuppressor.SuppressFilter from any code that has access to HttpContext, typically in a controller action before returning the view:

using cloudscribe.Web.Navigation;

public IActionResult MyLandingPage()
{
    // suppress both the top menu and breadcrumbs on this page
    NavigationSuppressor.SuppressFilter(HttpContext, NamedNavigationFilters.TopNav);
    NavigationSuppressor.SuppressFilter(HttpContext, NamedNavigationFilters.Breadcrumbs);

    return View();
}

You could also call it from middleware or an action filter if you want to suppress navigation based on a route convention or other criteria.

The suppression only affects the current request. There is nothing to clean up — HttpContext.Items is disposed automatically when the request ends.

As an example of this feature in use, cloudscribe Core uses NavigationSuppressor in its AccountController to optionally hide navigation on authentication pages, controlled by a per-site admin setting.