开发者

session state losing value

I have an asp.net application c# that uses session state to store a variable when the user logs 开发者_运维技巧in. This is their log in name and its used extensively throughout the user area. Problem is that the session keeps losing the information on certain computers. I dont know enough about session state really and i wanted to know why this was happening. An example. When a user goes through different selections on a grid, after about 2 mins the label which shows the session state variable on the screen is empty, causing problems for the person when they want to add a record as the database requires their username to stamp onto a record.

So in summary. what would cause a session state variable to lose its value after only a few minutes and not on all computers. ( i have no problem on my computer only on the clients machine- typical isnt it)

a little more information;

i use the session in the server side code, ie

  session["username"] = username.Text;

and also the hosting i have is a shared hosting environment which means i have very little to do with the iis settings (fairly cheap job im afraid) Will try the web config change and report back . Thanks for all the answers.


if I understand your issue, you have to storage your session data out of process. You could use "State Server Mode" or "SQL Server Mode" if you have a SQLServer database.

Here you can find how to use http://msdn.microsoft.com/en-us/library/ms178586.aspx

Otherwise you can built a "custom session state store provider", but I think that way is a bit more complicated.


It sounds like (though I could be wrong) that you have multiple IIS servers each maintaining state. If you're load balancing, there's no guarantee you'll hit the same server twice. So, while server A has the state information you're looking for, Server B will not.

Are you load balancing? If so, you might want to use SQL server for state management.


Maybe the session is timing out after 2min? The value should be in web.config in a line like

<sessionState timeout="40"></sessionState>

Or you could write a session timeout handler in global.asax and put a breakpoint in it to see if that's the cause.


There are multiple ways to store session state, the two most common are client side cookies and server side session. (we could get into session state servers and database stored session but I'd rather not)

when you say that other users are having issuse, but you are not makes me think that their session is probably expiring. It is hard to tell what users are doing all the time, but a good test would be to log in, let it sit for an hour or two and then come back to it to see if you still have session state. You can control the session time out in IIS and it can also be set in web.config. even though the config is "supposed" to override iis settings in most scenarios, it does not work well under these scenarios and you are better off updating the IIS and web config session state expiration.


I think you are heavily using session to store the values... use it when required only.

And here as you are facing frequent problem then check in IIS and increase the application pool for the website,as your web site would be using more memory then the allowed application pool so the IIS recycles the session and the session values are LOST.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜