Search code examples
asp.net-mvcasp.net-coreopenididentityserver4

Display Login/Logout on the client when using IdentityServer4


I have 2 clients and 1 IdentityServer4 applications.

I am using implicit flow and I would like to show login/logout label on my ASP .Net Core client page (top-right corner). What is the best way to do this ?

Is there any sample MVC Core application that is showing us how to do this ?

Thanks


Solution

  • You can check to see if a user is authenticated in your razor like so:

    @if (User.Identity.IsAuthenticated)
    {
        // html for logout button
    }
    else
    {
        // html for login button
    }