i have application following layout. in shared views folder have, _layout.cshtml, _sidenav.cshtml , _currentuser.cshtml.
in _layout.cshtml have:
@{ html.renderpartialif("_sidenav", request.isauthenticated); } in _sidenav.cshtml have:
@{ html.renderpartial("_currentuser"); } in _currentuser.cshtml have:
<div class="login-info"> <span> <a href="javascript:void(0);" id="show-shortcut" data-action="toggleshortcut"> <img src="~/content/img/avatars/sunny.png" alt="me" class="online" /> <span>@user.identity.name</span> <i class="fa fa-angle-down"></i> </a> </span> </div> we use formsauthentication authenticate user. not using standard identity authentication ships asp.net mvc 5 because using ldap server.
formsauthentication.setauthcookie(username, ispersistent); ..... httpcontext.current.user = new genericprincipal(new genericidentity(username, "forms"), roles); we use username in cookie can information ldap server.
problem: @user.identity.name returns username. need display full name of user. have access full name when authenticate. not sure how use it.
how can pass fullname value accountcontroller _currentuser.cshtml partial view? kind of global container @user.identity more attributes can set.
you can use this
formsauthenticationticket ticket = new formsauthenticationticket(1, viewmodel.email, your_issue_date, your_expire_date, viewmodel.rememberme, jsonconvert.serializeobject(user), formsauthentication.formscookiepath); string hash = formsauthentication.encrypt(ticket); httpcookie authcookie = new httpcookie(formsauthentication.formscookiename, hash); response.cookies.add(authcookie);
Comments
Post a Comment