How to hide my menu for unauthenticated users?

I have authenticated users to login using this code:

FormsAuthentication.SetAuthCookie(user, false); 

I want to hide my system menu for non-authenticated users. Something like that:

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

How can i do this?

Thanks.

+7
authentication asp.net-mvc
source share
4 answers
 if (Request.IsAuthenticated) 

(Here's how to do it in the default ASP.NET ASP.NET template)

+20
source share

if (Request.IsAuthenticated)

Here is an example of this in the mvc base project user control.

if you need roles then

if (HttpContext.Current.User.IsInRole ("myrole"))

+4
source share

I think you want to use:

 <% if(this.User.Identity.IsAuthenticated) { %> <% } %> 
+1
source share

I use:

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

or

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

but other answers look as if they are working fine too.

+1
source share

All Articles