TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Dr.Ajay Kashyap
NA
521
284.1k
How to use Session In Mvc
Dec 2 2016 6:43 AM
Hello...
i am using session in website and session expired time is 30 min ..but if some one access website continue from 30 min so how to reset time because its automatically logout..
this is my code
session Method :-
public class SessionExpire : System.Web.Mvc.ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
if (HttpContext.Current.Session["userid"] == null)
{
FormsAuthentication.SignOut();
HttpContext.Current.Session.Abandon();
filterContext.Result =
new RedirectToRouteResult(new RouteValueDictionary
{
{ "action", "Index" },
{ "controller", "Home" },
{ "returnUrl", filterContext.HttpContext.Request.RawUrl}
});
return;
}
}
}
This Is Controller:-
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ShopINdeal.Models;
using ShopINdeal.ViewModels;
using System.Data;
using System.Data.Entity;
using System.Web.Security;
using System.Data.Entity.Validation;
using System.IO;
using Microsoft.Ajax.Utilities;
using System.Net.Mail;
namespace ShopINdeal.Controllers
{
[SessionExpire]
public class WholeSaleController : Controller
{
public ShopINdealEntities4 db = new ShopINdealEntities4();
[HttpGet]
public ActionResult CreateWholeSale()
{
return View();
}
[HttpPost]
public ActionResult CreateWholeSale()
{
return View();
}
WebConfig:-
<system.web>
<sessionState cookieless="false" timeout="2" />
<authentication mode="None" />
<compilation debug="true" targetFramework="4.5.2" />
<customErrors mode="Off">
</customErrors>
<httpRuntime targetFramework="4.5.2" />
<httpModules>
<add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" />
</httpModules>
</system.web>
Reply
Answers (
4
)
Machine testing on MVC 5
How to Rename and compress image in MVC