0

I am using WebSecurity in my project, and sometimes it shows the current user id as -1 (but that user actually is Id = 1)

here is the code line

Obj.CreatedBy = WebSecurity.CurrentUserId;

Does anyone know why that happens? It is not that WebSecurity.CurrentId doesn't yeild be correct results, but it only did for 2 times. everything is working fine in my code, was just curious why that happened.

here is a snap of my db table records where it is saved as -1

here is a snap of my db table records where it is saved as -1

S.J.Lee
  • 23
  • 8
  • Possible duplicate of [Getting the CurrentUserID from Websecurity directly after login (C#/ASP.NET)](https://stackoverflow.com/questions/11262170/getting-the-currentuserid-from-websecurity-directly-after-login-c-asp-net) – Kitson88 Jul 06 '18 at 13:00
  • The `CurrentUserId` property returns -1 if there is no current user logged in. – Kitson88 Jul 06 '18 at 13:03
  • @Kitson88 i see. thanks. – S.J.Lee Jul 09 '18 at 04:16
  • @Kitson88 not exactly. my question was why -1 id happens. and the question you tagged above asks how to get the id of the logged in user as he is not getting it through websecurity.currentId. that is not my concern. i just wanted to know the reason why -1 appears, and that answer is nowhere mentioned in that question. the context is same but the answer we wanted are different. – S.J.Lee Jul 09 '18 at 04:26

0 Answers0