I'm new with ASP.NET MVC,
I moved an HTTP POST method from my controller to Helpers, and I can't call User.Identity.GetUserId() from System.Security.Principal.IIdentity library.
Why can I not use this library from the helpers? Thanks
I'm new with ASP.NET MVC,
I moved an HTTP POST method from my controller to Helpers, and I can't call User.Identity.GetUserId() from System.Security.Principal.IIdentity library.
Why can I not use this library from the helpers? Thanks
Copyright © 2021 Jogjafile Inc.
The
Userobject that you get from within the controller usingUser.Identity.GetUserId()is of typeHttpContext.User.You can get get the current
HttpContextby usingHttpContext.Currentwhich sits withinSystem.Web.You'll need the using statement for the Extension method too.
I personally would recommend passing this value in as a parameter from your controller if you're retrieving it within your helper methods because it makes it a bit more clear that it relies on it?
You will need to get this value from your controller and pass it as a parameter if you move the helper method into your service layer etc.