I'm new to ASP.NET MVC and am using version 1.0 of the framework. I have a site.master page with the following hard-coded menu
<div id="menucontainer">
<ul id="menu">
<li><%= Html.ActionLink("Home", "Index", "Home")%></li>
<li><%= Html.ActionLink("Drivers", "List/?category=Drivers", "Product")%></li>
<li><%= Html.ActionLink("Irons", "List/?category=Irons", "Product") %></li>
<li><%= Html.ActionLink("Wedges", "List/?category=Wedges", "Product") %></li>
<li><%= Html.ActionLink("Putters", "List/?category=Putters", "Product") %></li>
</ul>
</div>
I want to show an extra item on the menu only if users are logged on. Something like "View My Listings". I have no problem doing this in a dirty hacky way so I have tried
<% if (User.Identity.IsAuthenticated) ...
but User
is not valid in this context. My question is how to show an extra menu item only if users are logged on?
For MVC 4+ We do like this:
@if(Context.User.Identity.IsAuthenticated) {
<li> @Html.ActionLink(...
}
I also just discovered that I could use
<% if (Request.IsAuthenticated) { %>
<li><%= Html.ActionLink("View my Listings", "MyListings", "List")%>
<% } %>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With