<commit_before>﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>ASP.NET Boilerplate documentation</title>
<link type="text/css" rel="stylesheet" href="bootstrap.min.css" />
<style type="text/css">
</style>
</head>

<body>

<ul>
	<li><a href="#DocIntroduction">Introduction</a></li>
	<li><a href="#DocInjectingSession">Injecting session</a></li>
	<li><a href="#DocUsingSession">Using session properties</a></li>
</ul>
<h3 id="DocIntroduction">Introduction</h3>
<p>If an application requires login, it also needs to know the current user 
performing operations. While ASP.NET itself provides Session objects in the 
presentation layer, ASP.NET Boilerplate provides <strong>IAbpSession</strong> 
interface to obtain current user and tenant wherever needed.</p>

<div class="bs-callout bs-callout-warning">
	<h4>About IAbpSession</h4>
<p><span class="auto-style1">IAbpSession</span> 
interface must be implemented in order to get actual session informations. While you can 
implement it in your own way, it's fully implemented in <strong>module-zero</strong> 
project.</p>
</div>
<p>IAbpSession is also fully integrated and used by other structures in ASP.NET 
Boilerplate (setting system and authorization system for instance).</p>

<h3 id="DocInjectingSession">Injecting session</h3>
<p>IAbpSession is generally <strong>
<a href="/Pages/Documents/Dependency-Injection#DocPropertyInjection">
property injected</a></strong> to needed classes unless it's not possible to 
work without session informations. If we use property injection, we can use
<strong>NullAbpSession.Instance</strong> as default value as shown below:</p>
<pre lang="cs">public class MyClass : ITransientDependency
{
    public IAbpSession AbpSession { get; set; }

    public MyClass()
    {
        AbpSession = NullAbpSession.Instance;
    }

    public void MyMethod()
    {
        var currentUserId = AbpSession.UserId;
        //...
    }
}</pre>
<p>Since authorization is a application layer task, it's adviced to <strong>use 
IAbpSession in application layer and upper layers</strong> (we don't use it in 
domain layer normally). <strong>ApplicationService</strong>, <strong>
AbpController</strong> and <strong>AbpApiController</strong> base classes has
<strong>AbpSession</strong> already injected. So, you can directly use 
AbpSession property in an application service method for instance.</p>
<h3 id="DocUsingSession">Using session properties</h3>
<p>AbpSession defines a few key properties:</p>
<ul>
	<li><strong>UserId</strong>: Id of the current user or null if there 
	is no current user. It can not be null if the calling code is authorized.</li>
	<li><strong>TenantId</strong>: Id of the current tenant or null if there is 
	no current tenant.</li>
	<li><strong>MultiTenancySide</strong>: It may be Host or Tenant.</li>
</ul>
<p>UserId and TenantId is <strong>nullable</strong>. There is also non-nullable
<strong>GetUserId()</strong> and <strong>GetTenantId()</strong> methods. If 
you're sure there is a current user, you can call GetUserId(). If current user 
is null, this method throws exception. GetTenantId() is also similar.</p>

</body>

</html><commit_msg>How to change IAbpSession to a specific user/tentant<commit_after>﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>ASP.NET Boilerplate documentation</title>
<link type="text/css" rel="stylesheet" href="bootstrap.min.css" />
<style type="text/css">
</style>
</head>

<body>

<ul>
	<li><a href="#DocIntroduction">Introduction</a></li>
	<li><a href="#DocInjectingSession">Injecting session</a></li>
	<li><a href="#DocUsingSession">Using session properties</a></li>
</ul>
<h3 id="DocIntroduction">Introduction</h3>
<p>If an application requires login, it also needs to know the current user 
performing operations. While ASP.NET itself provides Session objects in the 
presentation layer, ASP.NET Boilerplate provides <strong>IAbpSession</strong> 
interface to obtain current user and tenant wherever needed.</p>

<div class="bs-callout bs-callout-warning">
	<h4>About IAbpSession</h4>
<p><span class="auto-style1">IAbpSession</span> 
interface must be implemented in order to get actual session informations. While you can 
implement it in your own way, it's fully implemented in <strong>module-zero</strong> 
project.</p>
</div>
<p>IAbpSession is also fully integrated and used by other structures in ASP.NET 
Boilerplate (setting system and authorization system for instance).</p>

<h3 id="DocInjectingSession">Injecting session</h3>
<p>IAbpSession is generally <strong>
<a href="/Pages/Documents/Dependency-Injection#DocPropertyInjection">
property injected</a></strong> to needed classes unless it's not possible to 
work without session informations. If we use property injection, we can use
<strong>NullAbpSession.Instance</strong> as default value as shown below:</p>
<pre lang="cs">public class MyClass : ITransientDependency
{
    public IAbpSession AbpSession { get; set; }

    public MyClass()
    {
        AbpSession = NullAbpSession.Instance;
    }

    public void MyMethod()
    {
        var currentUserId = AbpSession.UserId;
        //...
    }
}</pre>
<p>Since authorization is a application layer task, it's adviced to <strong>use 
IAbpSession in application layer and upper layers</strong> (we don't use it in 
domain layer normally). <strong>ApplicationService</strong>, <strong>
AbpController</strong> and <strong>AbpApiController</strong> base classes has
<strong>AbpSession</strong> already injected. So, you can directly use 
AbpSession property in an application service method for instance.</p>
<h3 id="DocUsingSession">Using session properties</h3>
<p>AbpSession defines a few key properties:</p>
<ul>
	<li><strong>UserId</strong>: Id of the current user or null if there 
	is no current user. It can not be null if the calling code is authorized.</li>
	<li><strong>TenantId</strong>: Id of the current tenant or null if there is 
	no current tenant.</li>
	<li><strong>MultiTenancySide</strong>: It may be Host or Tenant.</li>
</ul>
<p>UserId and TenantId is <strong>nullable</strong>. There is also non-nullable
<strong>GetUserId()</strong> and <strong>GetTenantId()</strong> methods. If 
you're sure there is a current user, you can call GetUserId(). If current user 
is null, this method throws exception. GetTenantId() is also similar.</p>

<p>
When testing your application you might want to <strong>change IAbpSession
to a specific user/tenant.</strong> You can acomplish this by using the <strong>Login()</strong> method 
in <strong>AbpUserManager</strong>.
</p>

</body>

</html>
{'fraction_non_alphanumeric': 0.12652417156792425, 'fraction_numerical': 0.006024960550853536, 'mean_word_length': 5.0155306298533215, 'pattern_counts': {'":': 0, '<': 201, '<?xml version=': 0, '>': 201, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1867467', 'n_tokens_mistral': 2164, 'n_tokens_neox': 2104, 'n_words': 713}