Concealing the navigation bar on an ASP.NET webpage following user login

I recently completed my first web application using ASP.NET.

https://i.sstatic.net/8HRQj.png

Now, I have the top navigation (red arrow) displayed on all pages of my web app. How can I hide it from specific pages so that users only see the side navigation (purple arrow)?

Do I need to make changes in the controller or in my _Layout.cshtml file?

Below is the code snippet for this page:


@{
    /**/

    ViewBag.Title = "AfterLogin";
}
<link href="~/Content/SidebarMenu.css" rel="stylesheet" />
<link href="~/Content/TOdo.css" rel="stylesheet" />
<script src="~/Scripts/todo.js"></script>
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap-theme.min.css">
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css">
<script src="//netdna.bootstrapcdn.com/bootstrap/3.0.3/js/bootstrap.min.js"></script>
<h2>To Do App</h2>

@if (Session["UserID"] != null)
{

    <div>
        Welcome : <a href="#"> @Session["UserName"] </a><br />
        <a href="/Register/Logout"> Logout</a>
    </div>


    <html>
    <head>

    </head>


    <body>
        <div class="area"></div><nav class="main-menu">
            <ul>
                <li>
                    <a href="http://justinfarrow.com">
                        <i class="fa fa-home fa-2x"></i>
                        <span class="nav-text">
                            Dashboard
                        </span>
                    </a>

                </li>
<!-- More list items here -->
            </ul>

            <ul class="logout">
                <li>
                    <a href="/Register/Logout">
                        <i class="fa fa-power-off fa-2x"></i>
                        <span class="nav-text">
                            Logout
                        </span>
                    </a>
                </li>
            </ul>
        </nav>




        <body>
            <!-- Your additional content here -->
        </body>







</html>



}

AND here is the _Layout.cshtml code:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>@ViewBag.Title - My ASP.NET Application</title>
    @Styles.Render("~/Content/css")
    @Scripts.Render("~/bundles/modernizr")
    @Scripts.Render("~/bundles/jquery")

</head>
<body>
    <div class="navbar navbar-inverse navbar-fixed-top">
        <div class="container">
            <div class="navbar-header">
                <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
                @Html.ActionLink("Application name", "Index", "Home", new { area = "" }, new { @class = "navbar-brand" })
            </div>
            <div class="navbar-collapse collapse">
                <ul class="nav navbar-nav">
                    <li>@Html.ActionLink("Home", "Index", "Home")</li>
                    <li>@Html.ActionLink("About", "About", "Home")</li>
                    <li>@Html.ActionLink("Contact", "Contact", "Home")</li>
                </ul>
            </div>
        </div>
    </div>
    <div class="container body-content">
        @RenderBody()
        <hr />
        <footer>
            <p>&copy; @DateTime.Now.Year - My ASP.NET Application</p>
        </footer>
    </div>

    @Scripts.Render("~/bundles/jquery")
    @Scripts.Render("~/bundles/bootstrap")
    @RenderSection("scripts", required: false)
</body>
</html>

Answer №1

In the Layout.cshtml file, the navigation bar is not displayed when a user is logged in. Pay attention to this line: '@if(!User.Identity.IsAuthenticated)'

                <!DOCTYPE html>
            <html>
            <head>
                <meta charset="utf-8" />
                <meta name="viewport" content="width=device-width, initial-scale=1.0">
                <title>@ViewBag.Title - My ASP.NET Application</title>
                @Styles.Render("~/Content/css")
                @Scripts.Render("~/bundles/modernizr")
                @Scripts.Render("~/bundles/jquery")

            </head>
            <body>
                @if(!User.Identity.IsAuthenticated) 
                {
                    <div class="navbar navbar-inverse navbar-fixed-top">
                        <div class="container">
                            <div class="navbar-header">
                                <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
                                    <span class="icon-bar"></span>
                                    <span class="icon-bar"></span>
                                    <span class="icon-bar"></span>
                                </button>
                                @Html.ActionLink("Application name", "Index", "Home", new { area = "" }, new { @class = "navbar-brand" })
                            </div>
                            <div class="navbar-collapse collapse">
                                <ul class="nav navbar-nav">
                                    <li>@Html.ActionLink("Home", "Index", "Home")</li>
                                    <li>@Html.ActionLink("About", "About", "Home")</li>
                                    <li>@Html.ActionLink("Contact", "Contact", "Home")</li>
                                </ul>
                            </div>
                        </div>
                    </div>
                }
                <div class="container body-content">
                    @RenderBody()
                    <hr />
                    <footer>
                        <p>&copy; @DateTime.Now.Year - My ASP.NET Application</p>
                    </footer>
                </div>

                @Scripts.Render("~/bundles/jquery")
                @Scripts.Render("~/bundles/bootstrap")
                @RenderSection("scripts", required: false)
            </body>
            </html>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

SASS malfunctioning, error messages popping up in command prompt while running gulp serve

As I develop a web app using AngularJS and Gulp, I encounter an issue where the CSS does not seem to work when running 'gulp serve'. Despite attempting to reinstall various components like node_modules, Node.js, and Gulp, the same error persists. ...

Tips for making dropdowns stay visible in Vue.js with Tailwind CSS

Looking to create a dropdown menu using Vue.js and Tailwind CSS. Currently, when hovering over the "Genres" link, the dropdown appears but disappears as soon as the mouse moves away. Is there a way to keep it visible as long as the mouse is over the dropdo ...

Non-IIFE Modules

Check out this discussion on Data dependency in module I have several modules in my application that rely on data retrieved from the server. Instead of implementing them as Immediately Invoked Function Expressions (IIFEs) like traditional module patterns ...

When utilizing the JavaScript createElement() method to create elements on keydown, it will not be compatible with jQuery's draggable() method

I'm currently developing a drag and drop feature for a project, allowing users to add items to a work area and then position them by dragging. I'm facing an issue where I want to create multiple instances of the same element using a key code, but ...

Accessing the ItemTemplate control from the ItemCommand event within a Repeater: Implementing this operation

My Repeater snippet: <asp:Repeater ID="rptrContacts" runat="server" OnItemCommand="rptrContact_ItemCommand" > <div ID="itemTemplate> <ItemTemplate> <%# Eval("Name") %> <%# Eval("Email") %> <asp:LinkButton ID="lbtnEditCont ...

Generate three separate inline blocks and position elements within them without any impact on the neighboring blocks

In my attempt to create three blocks with set height and width, aligned on top/bottom with a couple of elements inside each one, I encountered an issue. Whenever I add additional DIVs to one of the elements (resulting in a different number of DIVs inside e ...

URL resolution issue encountered with AJAX operation

My goal is to submit an HTML form to a Flask endpoint called /add_int. I'm using jQuery to intercept the form submission and send it to the endpoint using AJAX. Here's the code snippet: var form = $( this ).serialize() $.post({ ...

Vue Service - 401 (Access Denied)

Whenever I attempt to execute the "getUserData" method, it results in a 401 (Unauthorized) error. Strangely enough, when I make a GET request to the URL "" with the same headers in Postman, it works perfectly fine! How can I properly set my request heade ...

Various image resolutions designed for extra small, small, medium, and large screens

My image has a relative width and currently the src points to a single, large file (approximately 1000px). The issue arises on small devices with Opera and IE where the browser scaling results in pixelated images. Conversely, using a smaller image leads to ...

Error encountered with the $get method of AngularJS Provider during configuration() function

Recently, I configured a Provider that fetches a language JSON file from a web server and delivers it to Angular within the config() method. Here is the provider setup: .provider('language', function () { var languageWsURL , languageC ...

What is the process for using jQuery to systematically alter the src attribute of all avatar images on Twitter.com?

Summary: I am learning JavaScript and jQuery, and wanted to write a script to replace "_normal.png" with ".png" for all "img.avatar" images on Twitter.com. I encountered an error which I will explain below. Background: Practice makes perfect, so I like to ...

What is the best way to position the left sidebar on top of the other components and shift them to the

Currently, I am working on a project to display NBA data fetched from an API. I am aiming to recreate the design showcased here: Dribbble Design My main challenge lies in overlaying the left sidebar onto the main box and shifting the components sligh ...

How can a list of objects in a JPA entity with a many-to-one relation to a data entity be sorted based on the result of a method call from the data entity?

In my JPA entity User, there is a OneToMany relation to a UserStats entity. I made changes to the code to use UserStats instead of storing victoryRatio directly in the User entity. Now, calculateVictoryRatio() method is implemented in the UserDetails entit ...

transfer the value of a method to a different component

In my Component called IncomeList, there is a method named sumValue. This method simply adds different numbers together to produce one value, for example 3+5 = 8. Similarly, in another Component named OutputList, the same logic is applied but with a method ...

Discover the method for concealing a button using ng-show and ng-hide directives

<div> <div class="pull-right"> <button type="button" data-ng-click="editFigure()" id="EditFigure">Edit Figure </button> <button type="button" data-ng-click="figurePreview()" id="PreviewFigure">Figure Previ ...

The error message from the mongoose plugin is indicating a problem: it seems that the Schema for the model "Appointment" has not been properly registered

I need help troubleshooting a mongoose error that is being thrown. throw new mongoose.Error.MissingSchemaError(name); ^ MissingSchemaError: Schema hasn't been registered for model "Appointment". Use mongoose.model(name, schema) I have double-c ...

adjusting the size of buttons depending on the quantity of items displayed

Currently in my Angular application, I am working on rendering buttons within the view using the *ngFor directive. My goal is to have the rendered buttons appear side by side. While I have achieved this, I now want to dynamically resize each button based o ...

Pagination using Laravel 4, Angular JS, and the latest Twitter Bootstrap 3 features

Update: In my application built with Laravel 4 and Angular JS, I am in need of pagination functionality. While there is an option to use the angularui-bootstrap pagination, I have decided to explore and integrate the features of Laravel pagination with An ...

Linking states using AngularJS and jQuery

Imagine I have a scenario with two different states: .state('page1', { url: '/page1', templateUrl: 'pages/templates/page1.html', controller: 'page1' }) .state('page2', { url: '/page2& ...

Using handlebars JS within URLs

Trying to implement handlebars to display a URL in an email HTML template that is sent to a user for confirmation after registration. The link is created in the following way: var data = { user: { email: body.email, ...