Click here to Skip to main content
Rate this: bad
good
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 asp.net 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))
 {
 <div>
 
 <input type="text" name="LoginName" id="LoginName" />
 <input type="password" name="Password" id="Password" />
 
 <p>
  <input type="checkbox" name="RememberMe" /><span>Remember me?</span></p>
 
  <input id="Submit1" type="submit" value="submit" />
 
  </div>
 }
 
[HttpPost]
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();
  Session.Add("user",aUser.UserId);
  return RedirectToAction("Index", "Home");
 }
 else
 {
   return RedirectToAction("Login", "User", new { error = "login" });
 }
Posted 30-Jul-12 22:32pm
askquez379
Edited 31-Jul-12 0:33am
v2

1 solution

Rate this: bad
good
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 ?
  Permalink  
Comments
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 Sergey Alexandrovich Kryukov 545
1 OriginalGriff 285
2 Shweta N Mishra 244
3 BillWoodruff 230
4 Mathew Soji 225
0 OriginalGriff 6,153
1 Sergey Alexandrovich Kryukov 5,758
2 DamithSL 4,958
3 Manas Bhardwaj 4,539
4 Maciej Los 3,735


Advertise | Privacy | Mobile
Web02 | 2.8.1411019.1 | Last Updated 31 Jul 2012
Copyright © CodeProject, 1999-2014
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