Arif Hussain

Arif Hussain

  • NA
  • 17
  • 4.1k

How to increase Session timeout in C# MVC web application?

Jan 20 2021 9:41 AM
Hi,
 
I am developing an web application in c# MVC, I am facing an issue in login session time. After few minutes login when I refresh the page or go to another page, it will logout and redirect to login page. I also set the "timeout="1440" in web.config file. Kindly go through following code.
 
WEB.CONFIG
  1. <system.web>  
  2. <compilation targetFramework="4.5" tempDirectory="C:\Inetpub\vhosts\webdealsinv.com\tmp" />  
  3. <httpRuntime targetFramework="4.5" />  
  4. <authentication mode="Forms">  
  5. <forms loginUrl="Home/Login" timeout="1440" slidingExpiration="true" />  
  6. </authentication>  
  7. <roleManager enabled="true" defaultProvider="InvRoleProvider" cookieTimeout="1440">  
  8. <providers>  
  9. <clear />  
  10. <add name="InvRoleProvider" type="Inventory.Helper.InvRoleProvider" />  
  11. </providers>  
  12. </roleManager>  
  13. <httpHandlers>  
  14. <add path="*.less" verb="GET" type="dotless.Core.LessCssHttpHandler, dotless.Core" />  
  15. <add verb="GET" path="routejs.axd" type="RouteJs.RouteJsHandler, RouteJs" />  
  16. </httpHandlers>  
  17. <membership userIsOnlineTimeWindow="1440" />  
  18. <sessionState mode="InProc" timeout="1440" cookieless="false" />  
  19. </system.web>  
LOGIN ACTION
  1. [HttpPost, AllowAnonymous]  
  2. public ActionResult Login(InvUser invuser)  
  3. {  
  4. string result = objData.CheckUser(invuser);  
  5. if (result == "Success")  
  6. {  
  7. InvUser _invuser = objData.GetUser(invuser);  
  8. FormsAuthentication.SetAuthCookie(_invuser.UserID.ToString() + "|" + _invuser.FirstName, true);  
  9. return RedirectToAction("Index""Admin");  
  10. }  
  11. else  
  12. {  
  13. ViewBag.Msg = "Invalid Email or password!";  
  14. return View();  
  15. }  
  16. }

Answers (8)