Click here to Skip to main content
15,886,756 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
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..

XML
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>
 }


SQL
[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
Updated 30-Jul-12 23:33pm
v2

1 solution

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 ?
 
Share this answer
 
Comments
askquez 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 31-Jul-12 4:16am    
One minute is an insanely short session timeout. You're saying it's set to that ?
askquez 31-Jul-12 4:29am    
I have set 2880 minute time out but it is not working.. <sessionstate timeout="2880">
Christian Graus 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 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.

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900