Click to See Complete Forum and Search --> : Login system - displaying different content to logged-in users


invisible kid
03-13-2006, 07:01 PM
I have created a site with a user login system, using forms-based authentication.

On certain pages, I want users who are logged in to see certain content, e.g. at a simple level a line saying "Hello username, you are logged in".

However, when a user who isn't logged in looks at the same page, they should see different content, e.g
"You are not logged in, please click here".

Also, for the login form, I am using a user control which sits on every single page (so you can login from any page). However, I would want that to disappear once the user is logged in.

I know this simple, but I just can't work out how to do it!

I know I can re-direct the user to a secure sub-directory once they've logged in, but this would require making duplicate copies of each page (one in the root for non-logged in users, and one in the secure area for logged-in users).

As a side note, when using the line "Response.Write(this.Page.User.Identity.Name + " is logged in")" inside a class in a control, I found that this did not display the user name after the user clicked the login button, but only once the user actually clicked refresh.

Any help would be greatly appreciated.

Thanks,
Steve

invisible kid
03-13-2006, 07:18 PM
I should add that I am using framework 1.1.

takkie
03-14-2006, 03:03 PM
if you are using forms authentication, i am assuming that you have some sort of flag saying either the user is autheticated or not? (if you are doing this manually, i suggest you use the forms authentication with the web.config, which creates a cookie at the client, and all you have to check is, IsAuthenticated...

you put this in your web.config

<authentication mode="Forms">
<forms name="appNameAuth" path="/" loginUrl="login.aspx" protection="All" timeout="30">
</forms>
</authentication>

whenever someone goes to a page where he is not authenticated, it will redirect to login.aspx.

OR let say, you have a login control..you want to hide/unhide based on user is authenticated or not... you can do this.

in your web control's page_load event, you do, user.identity.isauthenticated, if it returns true, then you set me.visible = true, else false.

do the same with, Hello <username>, you are logged in.

-tak

TheLastBurden
04-11-2006, 06:53 AM
why not use Session Variables and populate them resp.

TheLastBurden
04-11-2006, 06:55 AM
why not use Session Variables and populate them resp.

takkie
04-13-2006, 03:19 PM
it sucks up webserver's resource for storing session variables. If the .net framework has a feature to do things like that, why not take advantage of it?

session variable will work, but i personally dont really like it..unless i have to use it..