check auth in EasyControl

Topics: Developer Forum
Feb 28, 2011 at 8:01 AM

In my EasyControl ascx file I would like to control the content based on Anonymus/Authenticated

i.e

If anonymus

<p>this is shown to anonymus users </p>

If Authenticated

<p> this is shown to authenticated users </p>

What asp do I have to put around these <p> tags

 

Henrik

Feb 28, 2011 at 2:27 PM

Hi Henrik,

Try the following;

 

<% if (Page.User.Identity.IsAuthenticated){ %>

Authenticated content here

<% } else { %>

Unauthenticated content here

<% } %>

 

For use with roles substitute the IsAuthenticated line with:

<% if (Page.User.IsInRole(MyWebPagesStarterKit.RoleNames.Administrators.ToString())){ %>

/Bjorn

Mar 6, 2011 at 1:06 PM

There is a LoginView control for that.

<asp:LoginView id="lv" Runat="server" >
<AnonymousTemplate>
You are not logged in.
</AnonymousTemplate>
<LoggedInTemplate>
here is a lot of stuff you can see when you are logged in ...
</LoggedInTemplate>
<asp:LoginView>

Also check out the LoginStatus and LoginName controls.