---
title: "Session object in mvc"  
description: "Session object in mvc"  
author: "Anonymous User"  
published: 2014-10-11  
updated: 2014-10-11  
canonical: https://www.mindstick.com/forum/2365/session-object-in-mvc  
category: "asp.net mvc"  
tags: ["asp.net", "asp.net mvc"]  
reading_time: 1 minute  

---

# Session object in mvc

i want to save some user [settings](https://www.mindstick.com/blog/63563/steps-to-change-the-wireless-settings-using-linksys-cloud-account) on [Session object](https://www.mindstick.com/forum/2484/how-to-retrieve-session-object-in-jsf-view). And get it from Session if i will need it. for this reason i want to create Base [Controller](https://www.mindstick.com/blog/273/passing-values-from-controller-to-view-in-asp-dot-net-mvc) which another [controllers](https://www.mindstick.com/forum/155773/how-asynchronous-controllers-work-in-asp-dot-net-mvc) are inherited from this BaseController. and want to [check](https://yourviews.mindstick.com/story/2248/never-forget-to-check-these-specifications-before-buying-a-mobile-phone) the session for null. if session is null then [redirect](https://www.mindstick.com/forum/2005/radio-button-redirect) to logon page. i have added.\

```
<authentication mode="Forms">      <forms loginUrl="~/Membership/LogOn" timeout="1" defaultUrl="~/Membership/LogOn" />    </authentication>
```

o webconfig file. after minute it redirects to LogOn page. But i know that my session wil end after 10 minutes. how i can make so that Session [objects](https://www.mindstick.com/forum/145447/what-are-objects) and httpContext.Request.IsAuthenticated die in same time?

and [please tell me](https://www.mindstick.com/forum/33900/please-tell-me-what-are-the-technique-to-content-optimization) in which [Event](https://www.mindstick.com/articles/167719/marquee-hire-benefits-of-event-lighting-hire-london) i must check session in BaseController. in OnActionExecuting?

## Replies

### Reply by Anonymous User

i did it. 1. I have created [session](https://www.mindstick.com/articles/12042/session-in-c-sharp) on Global.asax file in Session_Start() event 2. i have configured IIS so that my session will expire after (5 minute) 3. and added this section to web.config file. \

```
<authentication mode="Forms">          <forms loginUrl="~/Membership/LogOn" timeout="5" defaultUrl="~/Membership/LogOn" />    </authentication>
```

and now httpContext.Request.IsAuthenticated will return false when session expired. because timeout both of them is 5 minutes\


---

Original Source: https://www.mindstick.com/forum/2365/session-object-in-mvc

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
