-1

I need to share data (string, list, array) between two different aspx pages of the same application. What is the best way to do it if I do not want to use cookies and do not want for data to be visible in url.

a) Form post method
b) Session (cookies?)
c) Sql
d) Server.Transfer

Thanks

mko
  • 6,638
  • 12
  • 67
  • 118

2 Answers2

1

In-memory Session will be the simplest and quickest (development-wise) to store data between pages without their contents being visible in the query string (URL), like this:

To store a List<string> in Session, do this:

var listOfStrings = new List<string>();
listOfStrings.Add("1");
listOfStrings.Add("2");
listOfStrings.Add("3");

Session["ListOfStrings"] = listOfStrings;

To retrieve the List<string> from Session, do this:

// Check to see if item in Session is actually there or not
if(Session["ListOfStrings"] != null)
{
    // Cast the item in Session to a List<T>, because everything in Session is an object
    var myListOfStringsRetrieved = Session["ListOfStrings"] as List<string>;
}

Note: I am assuming you use C#, but this can easily be translated to VB.NET.

Karl Anderson
  • 34,606
  • 12
  • 65
  • 80
0

Some more details might be helpful. What type of information do you want to share? If it is something that needs to be saved, then perhaps it makes most sense to save the data in your database (or local storage, or what ever you are using) from one page and retrieve it in the other. If it's just temporary data, it probably makes more sense to post the data through a form, or use a session variable. The problem with the session variable is that you might time-out your session. A session variable wouldn't be my first choice.

The Jonas Persson
  • 1,726
  • 1
  • 17
  • 36