What is the best way to add a Member name to a session variable? I'm trying to set it up so I can direct them to specific pages base on name, here's the .NET code i nave so far.
Thanks!
Amir
public override bool CheckAuthentication() { // WARNING : DO NOT simply return "true". By doing so, you are allowing // "anyone" to upload and list the files in your server. You must implement // some kind of session validation here. Even something very simple as... // // // // ... where Session[ "IsAuthorized" ] is set to "true" as soon as the // user logs on your system. if (System.Web.HttpContext.Current.User.Identity.IsAuthenticated)
Do you have a good resource for getting other properties like role name? I'm having trouble searching for it, not sure if im just using the wrong terminology.
Yes, you should be able to find everything you need when it comes to Roles/UserGroups in the Roles class found in the System.Web.Security assembly. Here's an overview of the class:
add username to session variable
Hi,
What is the best way to add a Member name to a session variable? I'm trying to set it up so I can direct them to specific pages base on name, here's the .NET code i nave so far.
Thanks!
Amir
Hi Amir,
You should be able to set the session upon login. In your Login controls OnLoggingIn (or OnLoggedIn) you could maybe do this:
Session["UserName"] = HttpContext.Current.User.Identity.Name;
This stores the username of the logged in member as a session variable.
- Bo
Hi Bo, thanks for your help, so something like this?
public void OnLoggingIn()
{
Session["UserName"] = HttpContext.Current.User.Identity.Name;
}
Then retrieve it like this?
Hi Amir,
yes, that would be my guess :-) does it work?
Alternatively you could also just check on either HttpContext.Current.User.Identity.Name; or Member.GetCurrent().LoginName; before redirecting.
- Bo
Sure did! These are the two bits I used, thank you for your help!
-Amir
Bo,
Do you have a good resource for getting other properties like role name? I'm having trouble searching for it, not sure if im just using the wrong terminology.
Thanks!
Amir
Hi Amir,
Yes, you should be able to find everything you need when it comes to Roles/UserGroups in the Roles class found in the System.Web.Security assembly. Here's an overview of the class:
http://msdn.microsoft.com/en-us/library/system.web.security.roles.aspx
Hope that helps :) If not, let me know!
- Bo
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.