3

I have a situation where i want to input the details for anonymous Users also. So i have created a user id for them in Profile. When i am setting the user details

FormsAuthentication.SetAuthCookie(username, true);

I want the details relating to the user with User.Identity.Name with the username, but the User.Identity.IsAuthenticated to false. Right now i am getting it as true. I want to set this to true only after a particular login.

Shiva Saurabh
  • 1,281
  • 2
  • 25
  • 47

2 Answers2

4

The FormsIdentity class is hardwired to return true, always. So this cannot be changed. Even a GenericIdentity returns true whenever the name is not empty.

A workaround would be to create your own IIdentity implementation, and replace the forms identity in the Application_PostAuthenticateRequest event in Global.asax. It's a proven and safe solution.

Also please consider whether you really want to do this. It is good practice that unauthenticated users are anonymous, they have no name, and it is very elaborate why the built-in identity classes work the way they do.

fejesjoco
  • 11,763
  • 3
  • 35
  • 65
0

Unfortunately you cannot modify the User.Identity.IsAuthenticated to false. You can create your own cookie or you can assign a string variable for this user to session as a Dictionary. By this way you can modify the value and manually destroy that value for specific scenarios.

itatar
  • 1