0

I created registration and login to my app. But when I login i don't see logged user. How can I do that? I create all redirection to home page when user is connected but I don't see connected user like on this site.

enter image description here

I was fallowing this tutorial. And all is working fine. But how can I get this? On my site i have this:

enter image description here

My git. I didn't post any code, because is almost the same like in tutorial, except i added redirection to my home page. https://github.com/ivanradunkovic/Vozila/tree/master/Vozila Thanks

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>@ViewBag.Title - Vehicle</title>
    @Styles.Render("~/Content/css")
    @Scripts.Render("~/bundles/modernizr")
    <script type="text/javascript">
        var appInsights=window.appInsights||function(config){
            function s(config){t[config]=function(){var i=arguments;t.queue.push(function(){t[config].apply(t,i)})}}var t={config:config},r=document,f=window,e="script",o=r.createElement(e),i,u;for(o.src=config.url||"//az416426.vo.msecnd.net/scripts/a/ai.0.js",r.getElementsByTagName(e)[0].parentNode.appendChild(o),t.cookie=r.cookie,t.queue=[],i=["Event","Exception","Metric","PageView","Trace"];i.length;)s("track"+i.pop());return config.disableExceptionTracking||(i="onerror",s("_"+i),u=f[i],f[i]=function(config,r,f,e,o){var s=u&&u(config,r,f,e,o);return s!==!0&&t["_"+i](config,r,f,e,o),s}),t
        }({
            instrumentationKey:"615aadc5-8508-46e7-aa93-713181a155ae"
        });

        window.appInsights=appInsights;
        appInsights.trackPageView();
    </script>
</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("Vehicle", "Index", "Home", new { area = "" }, new { @class = "navbar-brand" })
            </div>
            <ul class="nav navbar-nav">
                <li>@Html.ActionLink("About application", "About", "Home")</li>
                <li>@Html.ActionLink("Vehicle Make", "Index", "Make")</li>
                <li>@Html.ActionLink("Vehicle Model", "Index", "Model")</li>
                <li>@Html.ActionLink("About author", "AboutAuthor", "Home")</li>
            </ul>
            <ul class="nav navbar-nav navbar-right">
                <li style="color: white; line-height: 50px;">
                <li>@Html.ActionLink("Login", "Login.aspx", "Login.aspx")</li>
                <li>@Html.ActionLink("Register", "Register.aspx", "Register.aspx")</li>
            </ul>
        </div>
    </div>
    <div class="container body-content">
        @RenderBody()
        <hr />
        <footer>
            <p>&copy; @DateTime.Now.Year - Vehicle by Ivan Radunković</p>
        </footer>
    </div>

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

My View/Shared/_Layout.cshtml

2

2 Answers 2

1

In shared/_Layout.cshtml you have to write code if user is loggedIn then display Name and Logg Off Text else show Login and Register Text(Button).

Like :

@if(Model.IsAuthenticated)
{
    <div>
      {Name(Fetch from model} Logg Off
    </div>
}
else
{
   <div> Register    Login
   </div>
}

Enjoy......

Sign up to request clarification or add additional context in comments.

2 Comments

I am not shure where to put that code? In my original post i edited and paste my _Layout.cshtml
1st you have to add IsAuthenticated property in your model and set it accordingly in action method before calling view.
1

If you can confirm that the users are being saved to the database then you just have to change your _Layout.cshtml:

@if(Model.IsAuthenticated)
{
    "Hello " + User.Identity.GetUserName()
}
else 
{
    <ul class="nav navbar-nav navbar-right">
        <li style="color: white; line-height: 50px;">
        <li>@Html.ActionLink("Login", "Login.aspx", "Login.aspx")</li>
        <li>@Html.ActionLink("Register", "Register.aspx", "Register.aspx")</li>
    </ul>
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.