I'm using my own authentication scheme, non-cookie based. I want to be able to manually set the Controller.User.Identity
with username and other data that I would normally set in a FormsAuthentication Cookie. Currently, the User Identity is being set by FormsAuthentication (I have no idea how, it just reads it from the encrypted cookie). How does FormsAuthentication do it? How would I do it?
Asked
Active
Viewed 258 times
0

Shawn Mclean
- 56,733
- 95
- 279
- 406
1 Answers
1
System.Web.HttpContent.Current.User = new GenericPrincipal(
new GenericIdentity("username", "CUSTOM"),
new string[]());
System.Threading.Thread.CurrentPrincipal = System.Web.HttpContent.Current.User;

Paul Fleming
- 24,238
- 8
- 76
- 113
-
Why do we set it 2 different place? What is `Thread.CurrentPrincipal` and `Current.User`? – Shawn Mclean Oct 21 '12 at 19:23
-
@Lolcoder See [here](http://stackoverflow.com/questions/3057937/difference-between-http-context-user-and-thread-currentprincipal-and-when-to-use). They have different life cycles. Also, dependencies may use one or the other (e.g. dependency A may use `System.Thread.CurrentPrincipal` whilst dependency B may use `System.Web.HttpContext.Current.User`) – Paul Fleming Oct 21 '12 at 19:27