0

I have an application where I have created a authhenticaton login with the help of entityframework IDENTITY.

The point of this application is alot but for the relevance of this question it is that it should be used by several users that even perhaps belog to different companies. For this I assigned an OrgId in the usertable in the DB.

The thing I am trying to figure out is the best way to get this OrgId. Every time a user logs in I get this info but I don't want to check the users info with each request or save to the db.

While searching for this i stumbled accross using a global variable like so:

ASP.NET MVC Global Variables

Which gives me an idea of how I can do this but I don't want to come to an impass weeks from now and realize that this was not the best way to go about doing this.

I'm searching for a good way of accomplishing what I am trying to do, pros, cons etc.

Community
  • 1
  • 1
ThunD3eR
  • 3,216
  • 5
  • 50
  • 94
  • 1
    If you dont want to use Identity with Claims, consider creating a custom IPrincipal that add the Organisation ID to the FormAuthenticationTicket so its available in each request. For a typical implementation, refer to [this question and its accepted answer](http://stackoverflow.com/questions/1064271/asp-net-mvc-set-custom-iidentity-or-iprincipal) –  Aug 31 '16 at 07:57

1 Answers1

0

If you're using ASP.NET Identity, I suggest using claims to set additional information about the user.

You can set the claims once the authentication is successful.

See the following for more information:

Link 1

Link 2

Community
  • 1
  • 1
DOMZE
  • 1,369
  • 10
  • 27
  • creating custom properties wasn't what I needed. I don't wan't to be requiered to call the user object to get info when saving some data or getting some data for a specific company. I have a potnetiall solution with assigning a global variable but I am trying to figure out if it is the right way to do it. Your answer is beoynd the question – ThunD3eR Aug 29 '16 at 17:23
  • The user identity object is already in the context, which is there for every request, so I don't see how bad it is – DOMZE Aug 29 '16 at 17:39