0

The general idea of the problem is that if you can imagine how you usually create a account on any given website. Once registered the actions you complete are against the account you have signed in as. Imagine your sign in contains multiple account yet you want the actions you complete to be specific to the individual account selected via a drop down menu.

All the pages are the same throughout the site you just have the choice who to complete the action against. Currently I am posting the users name along with each action I preform to allow me to figure out who to complete the action against. But I thought that someone might have a few ideas of how to do this better and achieve the same result in a much cleaner way?

As now all I'm doing at present is adding a select box to the top of each form (which reset to the default as the user navigates. Nasty I know!). I'm not sure if some sort of Helper might be a good solution to intercept all actions first and add a user name? Where I should maintain the current state of what username was selected, maybe a cookie or something else? Generally just confused about what sort of partner might work best for this problem.

Any ideas would be very much appreciated!

Sparkle
  • 2,459
  • 3
  • 18
  • 20
  • Session or Cookie seem like reasonable places to store the selected username. – Nathan Taylor Sep 06 '12 at 23:16
  • Thought about just maintaining a dropdown via javascript and a cookie which is passed with every request but it seems a little messy? having to grab it and set it all the time and having to write it into every post to be sent to the server? – Sparkle Sep 06 '12 at 23:22

1 Answers1

0

I think that the best way to check login status at server side and use standard FormsAuthentication, than you will have your active user name in User.Identity.Name.

So on logIn you should set auth coockie:

  FormsAuthentication.SetAuthCookie(username, true);

And on logOff or changing user:

  FormsAuthentication.SignOut();

This is pretty standard functionality, you could see it in default app that asp.net mvc 3 creates.

Links that you may need:

Community
  • 1
  • 1
Dmitry Zaets
  • 3,289
  • 1
  • 20
  • 33