/
------2016-05-15
/
------Introduction
If an app supports login, you may need to know some of the actions of the currently logged on user, but the ASP. NET itself provides session support for the presentation layer, and the ABP provides the Iabpsession interface to get (obtain) the current user and tenant anywhere
------About Iabpsession
This interface must be implemented to obtain the current session information, but you can also implement it in your own way, which is fully implemented in the Module-zero project.
Iabpsession is also fully integrated and used by other structures in the ABP (for this instance configuration system and authorization system)
------Injection SESSION
In general, Iabpsession is injected through attributes in the class that needs to use it, and if we use attribute injection, we can use Nullabpsession.instance as its default example as follows
public class Myclass:itransientdependency
{
Public iabpsession Abpsession{get;set;}
Public MyClass ()
{
Abpsession=nullabpsession.instance;
}
public void MyMethod ()
{
var Currentuserid=abpsession.userid;
//....
}
}
When the application layer requires authorization, it is recommended to use iabpsession on top of the application tier and application services (usually we do not use it at the domain level), Application,abpcontroller and Abpapicontroller have been injected abpsession , so you can use Abpsession's properties directly in the app service
Session Properties
Abpsession defines some key attributes
? UserID The ID of the current user, if none is null, it will not be null if the code is executed before it is authorized
? Tenatnid the ID of the current tenant is not NULL
? Impersonatoruserid
? Impersonatortenantid
? Multitenancyside
Userid and TenantId are nullable, there are non-empty methods GetUserId () and Gettenantid () methods, and if you determine that the current user exists, you can call GetUserId (), and if the current user is null, this method throws an exception, The same is true of Gettenantid ().
The impersonator property is not common and is typically used in audit logs.
User Identifier
You can use it in the iabpsession. Touseridentifier () extension method to create a Useridentifier object, since Useridentifier is used in numerous APIs, which makes it easy to create a user ID for the current user
ASP. Boilerplate-abpsession