2
votes

Suppose I have page1.aspx and page2.aspx, I am sending some data from page1 to page2 using query string and assigning to some variable.

There are some fields in page2 so user have to remain for some time before proceeding to next page (say page3).

Will variable of page2 which get value from query string change if second user also access to page2 which came from page1?
Edit:
Example: I have some folders like "txt/", "img/" and "temp/" in server and File Upload option in page1 where user can upload file and it will be saved in "temp/" folder. In the same page there is file extension check method and corresponding to extension, info will be send to page2,

Page1:

string filePath;
if(extension == "txt")
 {
  filePath = "txt/";
  Response.Redirect("Page2.aspx?filePath=" + filePath + "&fileName=" + fileName);
 }
 if(extension == "png")
 {
  filePath = "img/";
  Response.Redirect("Page2.aspx?filePath=" + filePath + "&fileName=" + fileName);
 }

Page2:

string fileName = HttpContext.Current.Request.QueryString["fileName"].ToString();
string filePath = HttpContext.Current.Request.QueryString["filePath"].ToString();
string savingPath = filePath + fileName;

and there is Save button in page2 to save the file.

user1 uploads txt file and comes to page2 and click Save button after 2 minutes, but before clicking save button by user1, a user2 uploads image file and comes to page2. So now will first file i.e txt file will be saved to "img" folder(which is my doubt) because filePath from query string becomes "img/" or everything will be done as expected means txt file will saved in "txt/"?

3
Give an example please.Swift
@Swift ,Question updated with example.ssa

3 Answers

5
votes

A query string parameter is stored by the browser in between requests, they are never stored on the server (as opposed to session variables for example). As such it can only ever be user independent.

Each new request to the server creates a new query string and passes the variables along with it.

I assume what you're doing is creating a link or button at the end of your Page2.aspx which contains the variables you'll need to pass to Page3. In this case what will happen is the HTML which is sent as part of Page2 will contain these addresses, the browser will store them until the user is ready to submit and use the url (along with any query string parameters) at that time.

3
votes

Your question should be more structured and clear. Try giving an example. In the mean time I will try to answer your question the way I understood it.

The query string is NOT user specific, it is request specific meaning query string parameters are not held anywhere but the querystring. This means that even if the same user accesses page2 through page1 a second time, the values in the original page2 will not be changed...

Different options to share variables in mvc:

  1. Querystring: only held in the querystring, lasts for 1 request, request specific
  2. Session: held in sessionstate on the server, lasts for the duration of the session (in general 20 minutes I believe), user specific
  3. ViewBag / ViewData: held on the server, lasts for 1 request, request specific
  4. TempData: held on the server, lasts for 1 request but can be used to transport data across controllers, request specific
  5. Cookies: held on the client, lasts for the duration of the cookie, user specific => Should be avoided as much as possible
2
votes

Based on your particular case above, the query string values between user1 and user2 will be totally independent. That means the first file uploaded by user1 will be saved to /txt folder and the second file uploaded by user2 will be saved to /img folder.

However, if both user1 and user2 upload files with the exact same name let's say abc.txt, then the first file from user1 will be overwritten by user2. You need to check the existence of the uploaded file name in page1 to avoid that. I would suggest renaming the uploaded file name by adding some incrementing number. For example, if user1 just uploaded abc.txt in page1, then when user2 also uploads abc.txt a bit later, change the file name to abc-1.txt, or to abc-2.txt if abc-1.txt also exists and so on. Hope that helps.