Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to hide my menu for non authenticated users?

I have authenticated users to log on my system using this code:

FormsAuthentication.SetAuthCookie(user, false);

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

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

How can I do this?

Thank you.

like image 770
MCardinale Avatar asked Aug 21 '09 15:08

MCardinale


3 Answers

if (Request.IsAuthenticated)

(This is how it's done in the default ASP.NET MVC template)

like image 198
CD.. Avatar answered Oct 22 '22 09:10

CD..


if (Request.IsAuthenticated)

There's an example of this in the login user control of the basic mvc project.

if you want roles then

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

like image 24
Russell Steen Avatar answered Oct 22 '22 10:10

Russell Steen


I think you want to use:

<% if(this.User.Identity.IsAuthenticated) { %>
<% } %>
like image 1
Joel Avatar answered Oct 22 '22 10:10

Joel