I've created movies (using the movies tutorial) and I want to hide the "create new" link so only a logged in user can see it.
I've tried searching for answers but can't find anything that helps me.
Any help would be appreciated.
I've created movies (using the movies tutorial) and I want to hide the "create new" link so only a logged in user can see it.
I've tried searching for answers but can't find anything that helps me.
Any help would be appreciated.
You could use something like the following. Use Request.IsAuthenticated to determine if the user is logged in.
@if (Request.IsAuthenticated)
{
<a href="@Url.Action("Index", "Manage")">
<i class="fa fa-user"></i>
<span class="text">Profile</span>
</a>
}
The easiest way to do it would be to wrap the ActionLink in an if clause like this
@if (User.Identity.IsAuthenticated)
{
@Html.ActionLink("link text", "action name");
}
but that's not really reusable and it mixes business concerns with your UI code.
Take a look at the this answer
How to override the ActionLink behavior
It's a real nice way to encapsulate the permission checking. Then just use @Html.AuthorizeActionLink in place of ActionLink.