显示菜单项只对登录的用户 [英] Show menu item only for logged-on users

查看:95
本文介绍了显示菜单项只对登录的用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我新的ASP.NET MVC和正在使用这个框架的1.0版本。我有以下的硬codeD菜单中的Site.Master页

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?

推荐答案

您可以通过上下文对象访问用户对象:

You can access the User object through the Context object:

<% if(Context.User.Identity.IsAuthenticated) ...

这篇关于显示菜单项只对登录的用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆