---
title: "How can we maintain sessions in MVC?"  
description: "How can we maintain sessions in MVC?"  
author: "Anonymous User"  
published: 2019-10-21  
updated: 2020-09-20  
canonical: https://www.mindstick.com/interview/33669/how-can-we-maintain-sessions-in-mvc  
category: "asp.net mvc"  
tags: ["c#", "asp.net mvc", "mvc"]  
reading_time: 2 minutes  

---

# How can we maintain sessions in MVC?

Sessions can be maintained in MVC by three ways: tempdata, viewdata, and viewbag.\
**Temp data** - This helps to maintain data when you move from one controller to another controller or from one action to another action. In other words, when you redirect, tempdata helps to maintain data between those redirects. It internally uses session variables.

**View data -** It helps to maintain data when you move from controller to view.

**View Bag -** This is a dynamic wrapper around view data. When you use Viewbag type, casting is not required. It uses the dynamic keyword internally.

## Answers

### Answer by Anonymous User

Sessions can be maintained in MVC by three ways: tempdata, viewdata, and viewbag.\
**Temp data** - This helps to maintain data when you move from one controller to another controller or from one action to another action. In other words, when you redirect, tempdata helps to maintain data between those redirects. It internally uses session variables.

**View data -** It helps to maintain data when you move from controller to view.

**View Bag -** This is a dynamic wrapper around view data. When you use Viewbag type, casting is not required. It uses the dynamic keyword internally.


---

Original Source: https://www.mindstick.com/interview/33669/how-can-we-maintain-sessions-in-mvc

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
