My problem is pretty simple - I think. I am running an ASP.NET MVC project. This is a project that requires the user to log in at all times. I probably need current user information in MasterPage, for example; "Howdy, Mark - you're logged in!"
But what if I need the same information in a view? Or some kind of check in my servicelayer?
So, how to make sure that this information is available when I need it, and where do I need it?
How much user information do you need? You can always access Thread.Current.Principal and get the username - and perhaps use it to find additional information about the user in the database.
Or, if you really really need some kind of information at any time, you can implement your own basic principle from IPrincipal (it really doesnβt matter!) And add these bits of information there, and when the user logs in, creates an instance of MyCustomPrincipal and attaches it to the current thread. Then it will be available everywhere, everywhere and at any time.
Mark
, . , , . , , , , , . , , , , , .
BaseController, , . , .., HttpContext.User.Identity.Name. .
. , .
, , - .
ModelBinder.
, , , , , ASP.net /.
( ) - , , , ASP.net. membershipProvider RoleProvider msdn, ( , , , !)
PS: Context.Users ! .
HttpContext.Current.Users.Identity returns the current user information. Although I'm not sure if it will be passed implicitly when you make a webservice call.
Source: https://habr.com/ru/post/1712933/More articles:Global.asax event: Application_OnPostAuthenticateRequest - authenticationNetBeans Refactoring for Hibernate Mapping Files - hibernateError updating SPPersistedObject from the web part - securityHow to Build a .NET Website Using Nant - .netHow do I write a WHERE clause in SQL Server for the following case? - sqlAm I having trouble replacing table and column names from top to camel with JPA? - jpaHow to use javascript math on version number - javascriptClick-out event for custom components in flex - flexINotifyPropertyChanged and INotifyCollectionChanged in F # using WPF - data-bindingIs an HttpContext.Current object even if an exception is thrown? - c #All Articles