I need to have a global Binary (Linq.Binary) variable (user reference), available for all controllers, which is filled in the process of authorization. I decided to use TempData. (May be, there is more suitable way?). I dont need MVC Membership system, only one variable.
When I close website, and then enter it again, my TempData is empty, and I need to restart authorization for user again. How to do it?
- [Authorize] did not work – user already authorized.
- I tried to insert this code in critical controllers:
if
(!TempData.ContainsKey(“CustomerRef”))
FormsAuthentication.RedirectToLoginPage();
but nothing happens.
- I tried to overload AuthoriseAttribute, but it looks impossible to look in TempData in AuthoriseAttribute class.
- I can’t store this variable in cookies – it’s critical.
- I dont want to store it somewhere in database.
The best way for me is to reset user authorisation some way, if TempData is empty, but I dont know, how to do it. Or, may be I’m re-inventing the wheel? 🙂
P.S.: I’m using TempData.Peek() while getting data, so variable didn’t flashes.
I’m trying to understand your question but it’s a little bit vague for me. So you wan’t to keep some extra critical user information when they are logged in?
I had a similiar situation , what I did was:
static Dictionary<String,someClassWithExtraValues>User.Identity.Name. That way I could always reach the values for the logged in users.You could use it in cookies even if it’s critical, once the FormsAuthentication cookie is manually changed it becomes invalid. Ofc there is still cookie stealing etc.