3

C# - ASP MVC - .NET 4.5 - Bootstrap - Razor

I have a form wizard (http://vadimg.com/twitter-bootstrap-wizard-example/examples/basic.html) that is used to setup a complex object (obj1). A property of obj1 is a List<obj2>. On one step of the wizard I want to add multiple obj2's to the list. Since obj2 is slightly complex as well, I thought I would use another wizard to help build it. Except I need to persist this List<obj2> on wizard 1, while I'm off in wizard 2 building another obj2.

My first thought was to use a session to hold the List<obj2>, I was just wondering if that's a good option, or if there would be a better one? The user may leave from Wizard1 to go to Wizard2 and come back multiple times.

davidkonrad
  • 83,997
  • 17
  • 205
  • 265
Will
  • 989
  • 4
  • 19
  • 33
  • 1
    Why are you ruling out persisting it in a database? – Simon Whitehead Sep 23 '13 at 22:54
  • All of the information needs to be populated before I can write to the database. Plus I'm trying to limit calls to the database where I can. – Will Sep 23 '13 at 23:07
  • So my question becomes why are you trying to limit calls to the database? Have you proven its a performance issue? You have to ask yourself these things.. because you're setting yourself for more pain than it is worth. Also, you're just trading database calls for memory usage (by using Session). – Simon Whitehead Sep 23 '13 at 23:08
  • There are basically only two places where you can store presistent data: memory (session in its default mode) or hard drive (DB). Each has its pros and cons but you need to pick one. – System Down Sep 23 '13 at 23:13
  • @Simon Whitehead This is actually a migration and expansion of an existing system to ASP MVC. Previously we had DB performance issues, that's my hesitation in making SQL calls. – Will Sep 23 '13 at 23:15
  • @SystemDown another option I was thinking about was storing the data in the page. It's not likely to be a large list, perhaps 3-5 items. – Will Sep 23 '13 at 23:17
  • What do you mean store it in the page? If you mean in the page's local variables that still means memory storage, and you're better off using sessions as they are easier to use across pages – System Down Sep 23 '13 at 23:20
  • As @Simon said, there are only two places to store DB or memory. For memory, you have one more option to have a cache server apart from asp .net session. You need to look at the amount of data you need to be keeping in memory and whether it has expiration time as well. – Muthu Sep 24 '13 at 02:30

1 Answers1

2

There's no perfect answer here; each approach has trade-offs. But here are some options that I can think of (and these are independent of ASP.NET/C#)

  • Session (as you suggest)
    • This will store data in web server memory (by default). If you have a lot of users, this could be a problem.
    • You risk the information being lost when the user gets a new cookie/the session times out.
    • Potentially better performance that a db, depending again on the number of users
  • Database (as you mentioned)
    • Could cause more database traffic.
    • Can save information for user even if they close a browser, switch computer, the power goes out, etc.
    • Maybe a separate NoSQL database just for transient wizard data would be worth trying.
  • Cookie (store data on the user's computer)
    • Users can potentially tamper with/view the data
    • There is a limit on cookie size (4 KB each?)
  • Local storage (HTML5)
    • Similar to cookies
    • But not such a small limit
    • Not every browser supports it (may need polyfill)
  • Form/Post/Hidden/ViewState
    • You could just post the data and drag the information from response to response
    • But this gets really annoying with back buttons & timeouts
    • Lots of work, and again, the user can tamper with the information
Matthew Groves
  • 25,181
  • 9
  • 71
  • 121