代码之家  ›  专栏  ›  技术社区  ›  MCardinale

如何为未经身份验证的用户隐藏我的菜单?

  •  7
  • MCardinale  · 技术社区  · 16 年前

    我已授权用户使用以下代码登录我的系统:

    FormsAuthentication.SetAuthCookie(user, false);
    

    我想为未经身份验证的用户隐藏系统菜单。像这样:

    <% if(???) {%>
       <ul id="menu>
          ...
       </ul>
    <% } %>
    

    我该怎么做?

    谢谢您。

    4 回复  |  直到 13 年前
        1
  •  20
  •   CD..    16 年前
    if (Request.IsAuthenticated)
    

    (这是在默认的ASP.NET MVC模板中进行的操作)

        2
  •  4
  •   Russell Steen    16 年前

    if(请求。已验证)

    在基本MVC项目的登录用户控制中有一个这样的例子。

    如果你想要角色,那么

    if(httpcontext.current.user.isinRole(“myRole”))

        3
  •  1
  •   Joel    16 年前

    我想你想用:

    <% if(this.User.Identity.IsAuthenticated) { %>
    <% } %>
    
        4
  •  1
  •   onof    13 年前

    我使用:

    <% if( HttpContext.Current.User.Identity.IsAuthenticated ) %>
    

    <% if( HttpContext.Current.User.Identity.IsInRole("roleName") ) %>
    

    但是其他的答案看起来也可以。