Reputation: 211
i used static variable to hold photo name and sign name and i passed these name to one page to another page through query string these work fine when i am run it in local system but when i am run it from server system and access through multiple client system and when redirect from one page to another page then there is photo name and sign name are same for all client system.
and when i m create a simple variable(not static) then it lost its value at the time of post back of page.
please give me solution for these how can i solve it
Upvotes: 1
Views: 2145
Reputation: 148110
You need to use Session instead of static variables. Sessions are unique for users while static variables are shared among all the objects.
ASP.NET session state enables you to store and retrieve values for a user as the user navigates ASP.NET pages in a Web application. HTTP is a stateless protocol. This means that a Web server treats each HTTP request for a page as an independent request. The server retains no knowledge of variable values that were used during previous requests. ASP.NET session state identifies requests from the same browser during a limited time window as a session, and provides a way to persist variable values for the duration of that session.
As a addition not If static members are being access by multiple thread then they must be considered for thread safety. This article give explanation of static members thread safety.
Upvotes: 3
Reputation: 22436
In ASP.NET, static variables are shared among all users as they are served by the same AppDomain in the w3wp-Process. When debugging the application on your development machine, you are the only user so you don't observe the same behavior.
Instead of using static variables, store the value in Session memory, e.g.:
Session["MySessionKey"] = variableValueThatYouWantToPreserve;
You can retrieve the value later on by reading from Session memory, e.g.:
var preservedValue = (PreservedValueType) Session["MySessionKey"];
For details on how to use Session memory, see this link.
If you transfer the value in a Request parameter when you access a new page and only need to preserve it on page-level, you can also use ViewState to preserve the value between PostBacks to the page.
Upvotes: 1