views:

46

answers:

1

How would you implement a user message stack in ASP.Net MVC? (you set messages for the user in any place inside your app. and they are shown as hints of your app to the user anywhere inside the app)

I want to hear your ideas and thoughts. How would you do it?

e.g.:

User stack message example

+3  A: 

I would use a combination of session and cookies to regulate the messages presented to the user. By doing this I would reduce the annoyance factor for the users and show them messages the least amount of times possible.

In MVC I would use a Partial View, that you can render on all your pages, and have it's behavior be independent of the site. Or have it be context aware.

Edit:

As mentioned in the comments, it can also be a good idea to store user dependent information in a database. This can allow for messages to be displayed to authenticated / known users. My original answer was mostly targeted at anonymous users.

For authenticated users, you could have a message table, with a read / not read bit, or even a simply push table where you push messages and delete them from the table once the user has seen it.

You may require a 2 part system. One for the messages displayed to anonymous users. The second part would be for authenticated users about their personal profile/events related to them or the site.

Alexandre Brisebois
Hi Alexandre, nice : ). I think the session would be a nice approach for non-durable messages. but if they're durable ("you have a new badge!!" for example) you need to persist them. : ) Thank you Alex +1
SDReyes
i truly agree that's why i mentioned the cookies.storing the profile information in a database, is also a great idea for authenticated users.
Alexandre Brisebois
@Alexandre Brisebois: Hi Alex! the read/not-read bit sounds great. nice idea. for the anonymous users, I think we could autogenerate a GUID per session and store the messages in the same way that authenticated users but using the session GUID. like the cart in the Music Store example http://www.asp.net/mvc/samples/mvc-music-store. Thanks Alex! +1
SDReyes
I'm not sure session guids would be good, because it would bloat your DB, and it would be the same as doing everything in the Session object. If you did anonymous messages with a State object serialized in the cookie. It would allow the users to pickup where they left off if they come back as anonymous. (using the same computer and same browser) this would also be stored on the users computer and not in your server where i presume space can be quite valuable or used for more important things.
Alexandre Brisebois