how to reterive session value in timer enabled event in mvc
how to enable session in timer enabled event in mvc 4 using c#
my code:
controller class
public ActionResult Home()
{
DateTime dt = DateTime.Now;
Session["forgotpassworduser"] = null;
Session["securityQuestion"] = null;
if (Session["username"] == null)
{
return RedirectToAction("Login");
}
Email ed = new Email();
var model = ed.receivedMessage(Session["username"].ToString()).ToList();
Timer timer = new Timer();
timer.Interval = (1000) * (10);
timer.Enabled = true;
timer.Elapsed += new ElapsedEventHandler(timer_call);
timer.Start();
return View(model);
}
public ActionResult checkevent(Models.EventCalender ec,string t)
{
if (ec.checkevent(DateTime.Now, t))
{
return RedirectToAction("loadCalender");
}
else
{
string url = this.Request.UrlReferrer.AbsolutePath;
if (url == null)
{
return Redirect(url);
}
}
return View();
}
private void timer_call(object sender, ElapsedEventArgs e)
{
EventCalender ec = new EventCalender();
string t2 = null;
try
{
t2 = Session["username"].ToString();
checkevent(ec, t2);
}
catch (Exception er)
{
string dt = er.ToString();
}
}
error is in this line t2 = Session["username"].ToString();