What can be use instead of session in MVC

Posted by Santosh4u under ASP.NET MVC on 5/26/2015 | Points: 10 | Views : 3647 | Status : [Member] | Replies : 3
Hi
i am very new to MVC and currently i got a requirement that i have to remove session from all the pages, so i should not store anything in session and have to replace with other concept to achieve this because don't logout from application.

currently in session i am just keeping login details and Module allowed and retrieving from other pages.you can see the below code to understand clearly

LoginCredential SessLogin = new LoginCredential();
SessLogin.ModuleAllowed = new List();
SessLogin.RLPEmpId ="V0008293"
SessLogin.RLPEmpName = "Santosh"
SessLogin.RLPEmpLocation = "India"

Var tempTop = somedatatable;
SessLogin.ModuleAllowed = tempTop;
Session["SessLogin"] = SessLogin;= SessLogin

---below two class used to assign value below storing in session.
public class LoginCredential
{
public string RLPEmpId { get; set; }
public string RLPEmpName { get; set; }
public string RLPEmpLocation { get; set; }
public List SECModule>; ModuleAllowed { get; set; }
}

public class SECModule
{
[Key]
[DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
public int ID { get; set; }
public int ParentID { get; set; }
public string ModuleName { get; set; }
}

hope you understood if not then let me know




Responses

Posted by: Sheonarayan on: 5/26/2015 [Administrator] HonoraryPlatinum | Points: 25

Up
1
Down
I think your original implementation was not right thats why you were told to remove all things from session. As per your statement ".... concept to achieve this because don't logout from application. ".

So is the requirement that the user was getting logged our automatically after 20 minutes or so? If that is the case, you can increase the timeout value (I saw there is no timeout sepecified and default is 20 minutes only).
Session.Timeout = 120;

If that doesn't solve the problem, you can keep all your details into cookies, however this seems not reliable as some browser doesn't allow cookies or user disable them.

Thanks

Regards,
Sheo Narayan
http://www.dotnetfunda.com

Santosh4u, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sheonarayan on: 5/26/2015 [Administrator] HonoraryPlatinum | Points: 25

Up
1
Down
You can't store an object in the cookies, however you can store each property of the object in different cookies. Read

http://www.dotnetfunda.com/articles/show/1402/how-to-create-cookies-in-aspnet
http://www.dotnetfunda.com/articles/show/1404/how-to-read-cookies-in-aspnet

Thanks

Regards,
Sheo Narayan
http://www.dotnetfunda.com

Santosh4u, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Santosh4u on: 5/26/2015 [Member] Bronze | Points: 25

Up
0
Down
Hi Shoen,
Yes, i can set the session timeout to more and it will work but the requirement is don't want to use session in application so asked me to use some other replacement of session .

cookie may be work but i don't know how to do...can i store class object( as you can see in my code) in cookie.if yes can u plz provide me that code to store and retrieve from cookie.

Thanks in advance..

Santosh4u, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response