Monday 15 March 2010

Setting session variables in a class is setting all of them, not just one -



Setting session variables in a class is setting all of them, not just one -

i have been researching way set session variables web app store logged in user's info. have made lot of progress, beingness novice, stumped why setting variables set of them , not 1 specified. can point out mistake(s), please? give thanks you!!

using system; using system.directoryservices; using system.security.principal; using system.web; using system.web.ui; namespace ithd { public class mutual : page { public static void getloggedinuserproperties() { string gloginid = extractusername(windowsidentity.getcurrent().name); sessionmanager.loginid = gloginid; verifyinad(gloginid); } private static void verifyinad(string suser) { seek { string username = extractusername(suser); directorysearcher search = new directorysearcher(); search.filter = string.format("(samaccountname={0})", username); search.propertiestoload.add("cn"); search.propertiestoload.add("memberof"); search.propertiestoload.add("givenname"); search.propertiestoload.add("sn"); search.propertiestoload.add("phone"); search.propertiestoload.add("title"); searchresult result = search.findone(); //sessionmanager.canedit = "false"; sessionmanager.username = string.empty; if (result != null) { sessionmanager.username = string.format("{0}", result.properties["cn"][0].tostring()); bool admin = checkgroup("helpdesk agents"); if (admin == true) { sessionmanager.hdagent = "true"; } } search.dispose(); } grab (exception ex) { sessionmanager.username = "guest"; } } public static string extractusername(string path) { string[] userpath = path.split(new char[] { '\\' }); homecoming userpath[userpath.length - 1]; } public static bool checkgroup(string group) { windowsidentity identity = windowsidentity.getcurrent(); windowsprincipal principal = new windowsprincipal(identity); homecoming principal.isinrole(group); } } public static class sessionmanager { private const string sloginid = ""; public static string loginid { { if (null != httpcontext.current.session[sloginid]) homecoming httpcontext.current.session[sloginid] string; else homecoming "guest"; } set { httpcontext.current.session[sloginid] = value; } } private const string susername = ""; public static string username { { if (null != httpcontext.current.session[susername]) homecoming httpcontext.current.session[susername] string; else homecoming "guest"; } set { httpcontext.current.session[susername] = value; } } private const string shdagent = ""; public static string hdagent { { if (null != httpcontext.current.session[shdagent]) homecoming httpcontext.current.session[shdagent] string; else homecoming "false"; } set { httpcontext.current.session[shdagent] = value; } } }

}

i don't think setting session keys correctly. in static class have property setter session session[""]=some value members. not need set key name of private fellow member in .net 3.5 not need private member. stuff whole session object in , not worry each member.

then access current instantiator of properties in

mysession.current.username="guest"; public class mysession { private const string _sessionname = "__my_session__"; //-------------------------------------------------------------------------------------------- private mysession(){} //-------------------------------------------------------------------------------------------- public static mysession current { { mysession session = (mysession)httpcontext.current.session[_sessionname]; if (session == null) { session = new mysession(); session.property1 = new property1(); session.property2 = new property2(); session.username = ""; httpcontext.current.session[_sessionname] = session; } homecoming session; } } public string username { get; set; } public property1 property1 { get; set; } public property2 property2 { get; set; } }

session session-variables

No comments:

Post a Comment