ASP. Boilerplate-abpsession

Source: Internet
Author: User
Tags app service

/
------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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.