Shawn Mclean
Shawn Mclean

Reputation: 57469

Manually set IIdentity

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?

Upvotes: 0

Views: 277

Answers (1)

Paul Fleming
Paul Fleming

Reputation: 24526

System.Web.HttpContent.Current.User = new GenericPrincipal(
    new GenericIdentity("username", "CUSTOM"),
    new string[]());
System.Threading.Thread.CurrentPrincipal = System.Web.HttpContent.Current.User;

Upvotes: 1

Related Questions