Click here to Skip to main content
11,798,866 members (75,094 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: MySQL EF MVC3
I am developing classified ads application in ASP.NET MVC3 using Entity Framework 4.3 for database.

I am facing problem when user session is active and execute any database query by entity framework then application session time's out unexpectedly.

Note that the query gets execute successfully and I can see my results as well but after a little while session terminates.

This only happen when I host my application to the live server (Arvixe). On my Local IIS it is working fine.

If I use any other source for database query then it is working fine.

I have also reset session time-out in web.config. I am using MYSQL. Any thoughts?

I am using this simple login method and it is working fine..

using (Html.BeginForm("ValidateLogin", "User", FormMethod.Post))
 <input type="text" name="LoginName" id="LoginName" />
 <input type="password" name="Password" id="Password" />
  <input type="checkbox" name="RememberMe" /><span>Remember me?</span></p>
  <input id="Submit1" type="submit" value="submit" />

public ActionResult ValidateLogin(string LoginName, string Password, string RememberMe)
  User aUser = new User(); //User Class
  var userList= db.Users.Where(u => (u.Loginname.ToLower() == name.ToLower() || u.Email == name) && u.Password == password);
 if (Users.Count() > 0)
  aUser = Users.Take(1).Single();
  return RedirectToAction("Index", "Home");
   return RedirectToAction("Login", "User", new { error = "login" });
Posted 30-Jul-12 21:32pm
Edited 30-Jul-12 23:33pm

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Have you set a really long timeout ? Is it timing out, or is it weird BECAUSE it doesn't take long enough to explain it ?
askquez at 31-Jul-12 4:15am
yes it is timing out because session goes null within 1 minute but on local iis it is working fine and when i query directly with MySqlCommand then working fine.
Christian Graus at 31-Jul-12 4:16am
One minute is an insanely short session timeout. You're saying it's set to that ?
askquez at 31-Jul-12 4:29am
I have set 2880 minute time out but it is not working..
Christian Graus at 31-Jul-12 5:04am
I had a similar issue today, I think it was something to do with the authorisation I was using. My solution was to redirect and put the value I needed on the URL instead of using the session. I think that the session in MVC can be flaky sometimes ( I had breakpoints in ALL code that resets the session, I was doing a redirect and in between one controller method and another, my session was disappearing ).
Christian Graus at 31-Jul-12 5:05am
Searching google now, I found one person who said that writing something to the session in your postback, keeps it alive. I am not convinced, I WAS writing to my session. I think you need to post a lot more detail ( are you using authorisation in your methods, are you doing an AJAX call or a POST, or a GET, etc ). Post some code.
askquez at 31-Jul-12 5:33am
I have update question..
Christian Graus at 31-Jul-12 5:54am
So when is your session lost ? You're doing your DB call, THEN putting stuff in the session, which is the opposite of what I thought you said.
askquez at 31-Jul-12 6:03am
After Login when session is active and call any db query then session times out
Christian Graus at 31-Jul-12 6:24am
OK, so this is the login code, which works, but the next time you access the DB, the session clears ? Does accessing the DB create any temporary files in the web app ? I was reading that if the folders are changed, the session resets.
askquez at 31-Jul-12 6:29am
No nothing any thing.just simple application.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 CPallini 505
1 OriginalGriff 503
2 Richard MacCutchan 321
3 Maciej Los 245
4 phil.o 244
0 OriginalGriff 2,270
1 Maciej Los 1,810
2 KrunalRohit 1,496
3 CPallini 1,425
4 Richard MacCutchan 1,109

Advertise | Privacy | Mobile
Web02 | 2.8.151002.1 | Last Updated 11 Mar 2015
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100