So, I am trying to build my first web api using MVC 4. All is going well. I managed to get basic authentication working with my site (using SSL) but I have a problem, sort of.
I have this tiny bit of code on every ApiController:
private Profile user
{
get
{
var UserId = Membership.GetUser(User.Identity.Name).ProviderUserKey.ToString();
var Profile = new Profile(UserId);
return Profile;
}
}
I do this, because my custom Profile has some extra fields in it; namely the CompanyId. All of my functions require this CompanyId to get data. I was thinking of using the CompanyId as a token, but I couldn't get that to work :D
So my question is: Is there a way of globally storing the CompanyId for each request? Perhaps in a filter to a route Message Handler. I know I can't use sessions, etc, because the API is stateless but on the other hand I don't want to have repetitive code all the time....