I'm using the DropCreateDatabaseAlways
Initializer so my database gets destroyed every time I start the application (at least I hope so). The funny thing is I still see myself as logged in. I get pass the Authorize
attribute and can do dangerous stuff. This is probably because of leftover cookies from previous testing.
Registration/login part of my app is the MVC 4 Internet Application template untouched. Shouldn't ASP.NET check the cookie values against users saved in the DB? WebSecurity.IsAuthenticated
returns true and WebSecurity.CurrentUserName
returns the name.
The only thing working as expected is WebSecurity.CurrentUserId
which returns -1. I'm a newbie so I can only guess this is because UserId
isn't stored in the cookie and must be retrieved from the database.
Am I right? If so, does it mean I should always use WebSecurity.CurrentUserId
to determine whether a user is logged in? WebSecurity.IsAuthenticated
and User.Identity.IsAuthenticated
seem pretty useless in that case. I can delete a user's account and he or she remains unaffected. What should be done differently if I am wrong?