I have a scenario where I need to access User.Identity
Claims in my Constructor's Controller.
I need this because the Claims have information required for me to spin up a custom DB Context (Connection String)
How can I go about accessing this? I would just inject in the DBContext, but based on the user, they may need to access a different DB.
Is there a better way to think about this?
[Authorize]
public class DefaultController : Controller
{
public DefaultController()
{
// this is NULL
var authenticatedUser = User.Identity.Name;
}
}
User
in the controller constructor will always be null. Nothing else you can do about it. Try using anActionFilter
.