-3

The use case is a user submitted form. I would like to redirect for the usability aspects of it, while also either displaying some feedback confirmation ('update was successful!') or error feedback ('you suck, go home!').

This data only needs to persist across a single redirect for a specific user (using Membership API).

I would prefer not to set up DB tables for this, and I don't like the idea of using Session cache for this either. HttpContext won't work, but I have considered using Cookies. I would have to be careful to stay under the 4kb limit (use keys+generic responses), but I thought I would see if there were other approaches I'm not considering.

John Saunders
  • 160,644
  • 26
  • 247
  • 397
Fred
  • 3,786
  • 7
  • 41
  • 52
  • 1
    I have edited your title. Please see, "[Should questions include “tags” in their titles?](http://meta.stackexchange.com/questions/19190/)", where the consensus is "no, they should not". – John Saunders Sep 13 '12 at 04:25
  • ah yes, stackoverflow: The question and answer site where the minutia is more important than the question. Or the answer. – Fred Sep 13 '12 at 04:28
  • 1
    why would you not use the session? – muratgu Sep 13 '12 at 04:30
  • 1
    You may have noticed that I'm not the only user of [so]. The fact that _I_ chose to edit your title does in no way indicate that others won't answer your question. – John Saunders Sep 13 '12 at 04:30
  • I love those impenetrable defenses as much as the next person, but lets get back to answering questions, shall we? – Fred Sep 13 '12 at 04:39

1 Answers1

1

You have the Post and the Get data.

The redirect is done using the Get, which means the ways to send data are:

  1. URL parameters only.
  2. Using a temporary place to store the data, like the session, or database, and pass the id of those data/message on URL parameters.

So if you have only two message to show, is just a simple http://example.com?msg=1 but if you would like to show more information you do not have much choice here - but:

In the action "Post/Redirect/Get" on the first Post you can make a decision - if the user has sent all the data correctly, and if all is OK then you do the redirect, and with this redirect you "only" say to the user, here is the data you entered, takes it from the DB and all is OK. If the Data is NOT correct, you do NOT make redirect, stay on page and show all the error messages about the data.


(source: planethost.gr)

So to summarize, you do the redirect only when the user has successfully entered the data and all is OK, and after the redirect you have only one message to show "that is OK" and here is the data.

Related: Post-Redirect-Get with ASP.NET

Cookies Absolutely forget about saving messages in cookies, they are not made for this purpose, they are limited in size, the cookie data is carried on all calls (even on the images) and the browser can even crash/or behave strangely with big size cookies.

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
Aristos
  • 66,005
  • 16
  • 114
  • 150
  • 1
    I ended up creating a generic key/value store using the DB and binary serialization, and using this to save/restore user feedback across redirects. I have a generic feedback system that hooks into the k/v store underneath (and other mechanisms use the k/v store as well, so it's not wasted effort). This is probably for the best as this app will eventually be load balanced, so things such as using the session store will break down the road. – Fred May 03 '13 at 19:19
  • @Fred Its looks easy at first, but its not. There are small details that must work together to make it do the job. So if you manage to make all that parts together and works - its good and cool and keep it. – Aristos May 03 '13 at 19:26
  • @Fred: I think Aristos deserves your **accepted answer** click ;-) – Oliver Feb 16 '16 at 13:59
  • I appreciate Aristos taking the time to answer, but his answer didn't answer the question. What he basically suggested is "don't do it", and that's not really what I was looking for. – Fred Jan 08 '17 at 20:06
  • @Fred I actually say you to do this way: `http://example.com?msg=1` with get data... (or maybe did not understand what you ask...) – Aristos Jan 09 '17 at 08:14