@if (Request.IsAuthenticated && User.Identity.Name=="administrator")
{
<div id="sidebar">
<div class="module">
<ul class="menu">
<li>@Html.ActionLink("Home", "Index", "Home")</li>
<li>@Html.ActionLink("About", "About", "Home")</li>
<li>@Html.ActionLink("Contact", "Contact", "Home")</li>
</ul>
</div>
<div class="mainContent">
Hello, @User.Identity.Name !
</div>
</div>
This is my layout if the user is authenticated as administrator but this sort of check looks no good, I need to check the role of the user not his name.
Here is the controler method
public ActionResult AuthenticatedUserLayout(string username)
{
var lst=userContext.UserProfiles.ToList();
var user = lst.Select(u => u.UserName == username);
if(IsAdmin(Session["LoginUser"].ToString())) return View(user); else return Index();
}
I also find that return View(user)
is no good, because I don't know how to make any use of that user
.