Reputation: 7852
I'm working on a CRUD ASP.NET WebForms web application consisting of a couple of pages in which the user fills in data. My client doesn't want to store the entities in the database between pages until the user clicks Finish on the last page (for various reasons). What options are there to propagate the filled in data between the pages and which is the least bad? From my readings I've seen that ViewState and Server.Transfer can be used. Any other options, preferably using less magic strings and more type safe data binding to entity objects?
Upvotes: 4
Views: 3493
Reputation: 89
Not sure what I am doing wrong, but my ASP Web API Controller does not have Session state available? I did this instead: (1) went to the WebApiConfig file, where that static class is defined, as I wanted some chunk of code that would run once before my controller ever gets called. In there I added a public static List variable, myList. (2) Then in the Register method, I finished defining that list. (3) Now over in my controller, I have a persistent (as long as I don't restart the app) list that I can read and write too.
public static class WebApiConfig
{
public static List<Note> myList;
public static void Register(HttpConfiguration config)
{
myList = new List<Note>();
myList.Add(new Note { Id = "1", Subject = "Wake up", Details = "Set alarm of 7:00 am and get out of bed." });
myList.Add(new Note { Id = "2", Subject = "Eat breakfast", Details = "Eat a healthy breakfast." });
myList.Add(new Note { Id = "3", Subject = "Go to work", Details = "Get to work before 9:00 am." });
// Web API configuration and services
// Web API routes
config.MapHttpAttributeRoutes();
... more code
And then in the Controller
public Note Save(Note newNote)
{
WebApiConfig.myList.Add(newNote);
return newNote;
}
Upvotes: 0
Reputation: 8164
Use MemCached.
there are tons of examples on the internet.
Try this :
Implementing Distributed Caching using Memcached
Upvotes: 1
Reputation: 18084
You can store all objects used in the client application in the Session
and then when the user clicks finish you send those objects to a service/method where you can convert them to entities and then submit them to the database.
Upvotes: 2
Reputation: 29744
Using ViewState
is going to significantly increase the amount of data your sending down the wire, as all Viewstate
data is serialised into a hidden input in the form, so as you add objects your HTTP request-response is going to grow significantly.
There's no magic bullet in this really. If your data is not too complex I'd store the values in the query string. If your objects are getting complex and big and you want to maintain type safety I'd use Session
, but remember to clean up after yourself!
a further option is to use the MVC paradigm and store the values in the form it's self using hidden inputs. This means you don't need to worry about clearing up your session if the user bugs out half way though but it also keeps your querystring clean.
think thats all your options, querystring, viewstate(don't do it), session or hidden variables.
Ok so you have to seraialise your data, so you cannot persist the context. this is not serialiseable so the above are your options:
they each have positive and negatives,
Take your pick!
Upvotes: 2