Skip to content

Instantly share code, notes, and snippets.

@b-tiwari
Last active November 6, 2017 04:50
Show Gist options
  • Select an option

  • Save b-tiwari/5279321149a86e98d6ffdf7dbe22b502 to your computer and use it in GitHub Desktop.

Select an option

Save b-tiwari/5279321149a86e98d6ffdf7dbe22b502 to your computer and use it in GitHub Desktop.
_loginPartial.cshtml - Claims based identity in MVC
@using Microsoft.AspNet.Identity
@if (Request.IsAuthenticated)
{
    using (Html.BeginForm("LogOff", "Account", FormMethod.Post, new { id = "logoutForm", @class = "navbar-right" }))
    {
    @Html.AntiForgeryToken()
    <ul class="nav navbar-nav navbar-right">
        <li>
            @Html.ActionLink("Hello " + @appUserClaims.GivenName + "!", "Index", "Manage", routeValues: null, htmlAttributes: new { title = "Manage" })
        </li>
        <li><a href="javascript:document.getElementById('logoutForm').submit()">Log off</a></li>
    </ul>
    }
}
else
{
    <ul class="nav navbar-nav navbar-right">
        <li>@Html.ActionLink("Register", "Register", "Account", routeValues: null, htmlAttributes: new { id = "registerLink" })</li>
        <li>@Html.ActionLink("Log in", "Login", "Account", routeValues: null, htmlAttributes: new { id = "loginLink" })</li>
    </ul>
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment