I was wondering how I could bind the IPrincipal to HttpContext.Current.User in Asp.net Mvc with Ninject.
Friendly greetings,
Pickels
Edit:
Not sure if it matters but I use my own CustomPrincipal class.
You can do this without the need for a provider in your NinjectModule
:
Bind<IPrincipal>()
.ToMethod(ctx => HttpContext.Current.User)
.InRequestScope();
Note, I included .InRequestScope()
to ensure that the value of the method is cached once per HTTP request. I'd recommend doing so even if you use the provider mechanism.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With