Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Css 如何在Visual Studio 2019中将左侧垂直边栏添加到.Net核心Web应用程序的默认模板_Css_.net_Asp.net Core - Fatal编程技术网

Css 如何在Visual Studio 2019中将左侧垂直边栏添加到.Net核心Web应用程序的默认模板

Css 如何在Visual Studio 2019中将左侧垂直边栏添加到.Net核心Web应用程序的默认模板,css,.net,asp.net-core,Css,.net,Asp.net Core,我想在.NETCore3.1的默认引导模板中添加一个左垂直边栏。登录后,此侧边栏必须仅对注册用户可见。 以下是_Layout.cshtml的代码: <div class="container"> @if (User.Identity.IsAuthenticated) { <div class="sidenav"> <a href="#about">About

我想在.NETCore3.1的默认引导模板中添加一个左垂直边栏。登录后,此侧边栏必须仅对注册用户可见。

以下是_Layout.cshtml的代码:

<div class="container">
    @if (User.Identity.IsAuthenticated)
    {

    <div class="sidenav">
        <a href="#about">About</a>
        <a href="#services">Services</a>
        <a href="#clients">Clients</a>
        <a href="#contact">Contact</a>
    </div>
    }
    <div class="main">

        <main role="main" class="pb-3">
            @RenderBody()
        </main>
    </div>
</div>

@ViewData[“Title”]-Agalber.hotel.Backoffice
  • 隐私
@RenderBody() &抄袭;2020年-Agalber.hotel.Backoffice-隐私 @RenderSection(“脚本”,必需:false)
假设您使用Asp.net core Identity登录网站,如果是这种情况,您可以检查
User
HttpContext.User.Identity.IsAuthenticated
是否正确,然后根据结果显示侧边栏

代码如下(_Layout.cshtml):

登录成功后,结果如下:


如果您不使用Asp.net core Identity,可以使用ViewData或TempData存储用户信息,然后在布局页面中,可以使用If语句检查ViewData或TempData是否为空,然后显示侧栏。

谢谢,主要是起到了作用,但我在水平面上看到了侧栏的元素。
    body {
        font-family: "Lato", sans-serif;
    }

    .sidenav {
        width: 130px;
        position: fixed;
        z-index: 1;
        top: 60px;
        left: 10px;
        background: #eee;
        overflow-x: hidden;
        padding: 8px 0;
    }

        .sidenav a {
            padding: 6px 8px 6px 16px;
            text-decoration: none;
            font-size: 25px;
            color: #2196F3;
            display: block;
        }

            .sidenav a:hover {
                color: #064579;
            }

    .main {
        margin-left: 140px; /* Same width as the sidebar + left position in px */
        padding: 0px 10px;
    }