asp.net mvc - Acessing Value from Global Variable in MVC -
hi developing web application using mvc4 , jquery mobile. in our each controller created user session below.
public class homecontroller : basecontroller { private static user currentuser;
public actionresult index(string name) { currentuser = (user)session["currentusersession"]; return view(); } public actionresult userdetaiks() { string username = currentuser.userfname; return view() }
}
above created object user model , assigned session value in index method. value in currentuser lost once entered userdetails. used static while creating object. question correct? or anyother way there. please guide me.
thanks guys 1 more doubt,
i used below code in form authenticate.
httpcookie authcookie = request.cookies[formsauthentication.formscookiename]; if (authcookie != null) { formsauthenticationticket authticket = formsauthentication.decrypt(authcookie.value); var s = new system.web.script.serialization.javascriptserializer(); user obj = s.deserialize<user>(authticket.userdata); userinformation currentuser = new userinformation(obj.userid); currentuser.userid = obj.userid; currentuser.firstname = obj.userfname; currentuser.lastname = obj.userlname; currentuser.roles = obj.securitygroupname; currentuser.defaultwarehouseid = obj.defaultwhseidentity; eg:14 httpcontext.current.user = currentuser; } **here user can change currentuser.defaultwarehouseid later currentuser.defaultwarehouseid = 16. when leave method. again getting value 14. can code currentuser.defaultwarehouseid 16 through out app 1 changed, please guide me.**
since there no guarantee, index method called before userdetails method, wouldn't use static variable store user. instead each controller method should user session required.
Comments
Post a Comment