<cite>ismcagdas: </cite> Hi @sago,
after navigating from this class to other custom service
Can you explain this ? I couldn't understand it.
It will be great if you can share your server-side and client-side code as well.
Okay ! I logged in to the application using admin privilleges, In the debug mode In UserAppService I can see all Session values, this class is decorated with attribute [AbpAuthorize()], when I navigate to the MyAppService the attribute [AbpAuthorize()] becomes InValid some how as it will not enter the requested method (decorated with attribute AbpAuthorize) and Session values are Null. This MyAppService is Inhierted from same base class ApplicationService. Again when I navigate to the UserAppService its Authorized and everything seems fine. I have problem with new created Services.
<cite>ismcagdas: </cite> Hi @sago,
Can you share your related code ?
This is where the user is Authorized and gets all service list from database..
[AbpAuthorize()] public async Task<List<UserNavigationHierarchyDto>> GetUserNavigationHierarchy(long UserId) { var vmUserNavigationHierarchy = await _sysobjectCustomRepo.GetUserNavigationHierarchy(UserId);
List<UserNavigationHierarchyDto> results = new List<UserNavigationHierarchyDto>();
foreach (var vm in vmUserNavigationHierarchy)
{
results.Add(new UserNavigationHierarchyDto
{
Id = vm.Id,
Name = vm.JsonName,
ParentId = vm.ParentId,
Code = vm.Code,
SystemObjectTypeId = vm.SystemObjectTypeId,
TenantId = vm.TenantId
});
}
return results;
}
After Navigating to a specific service, inside the class inherited from ApplicationService the same [AbpAuthorize()] is Invalid as it cannot enter the class or method requested! I am using ASPNET Core and ANGULAR 5. Node Modules abp-ng2-module v 2.1.0 OS-Win 10
After successful Login to the Application the AbpAuthorize is still not authorize to the logged in User restricting access to assigned services also the AbpSession.UserId is Null after navigation.
<cite>ismcagdas: </cite> UserId must be retrieved from claims, see <a class="postlink" href="https://github.com/aspnetboilerplate/aspnetboilerplate/blob/dev/src/Abp/Runtime/Session/ClaimsAbpSession.cs#L17">https://github.com/aspnetboilerplate/as ... ion.cs#L17</a>.
Can you use same code and debug it to see if claims contains userId or not ?
The session values exists in UserAppService, and after navigating from this class to other custom service the Abpsession.UserId becomes Null and the user is UnAuthorized to access this service [AbpAuthorize]. The user is successfully Logged and he is granted this permission using Roles.
<cite>ismcagdas: </cite> @sago what is your abp-ng2-module version ? Your problem might not be related to abp-ng2-module.
You can downgrade abp-ng2-module and see if it works for abp-ng2-module's older versions.
Downgraded didn't work, returned error Unexpected authenticateResult,
Angular 4 with core 1.1 works without any issue, Angular 5 with core 1.1 Under ABPSession object TenantId exists UserId becomes Null..
<cite>alper: </cite> try injecting the IAbpSession
public class MyClass : ITransientDependency { public IAbpSession AbpSession { get; set; } public MyClass() { AbpSession = NullAbpSession.Instance; } public void MyMethod() { var currentUserId = AbpSession.UserId; //... } }
Injection is already exists through Base class
Hi,
After upgrading to Angular 5 abp-ng2-module, AbpSession.UserId value is null in my custom module while tenant id exists, however this value seems to be exists in SessionAppService. With my previous version this is working fine, please advise.
Regards,
it's worked when i replaced (from ) to join :
public PagedResultDto<SalesInvoiceListingDto> InvoicesList(FilterDto input)
{
try
{
var query = from inv in _txSalesInfo.GetAll()
.WhereIf(
!input.Filter.IsNullOrWhiteSpace(),
u =>
u.Invoicenumber.Contains(input.Filter) ||
u.CustomerName.Contains(input.Filter) ||
u.Refrencenumber.Contains(input.Filter))
join org in _organizationUnitRepository.GetAll()
.WhereIf(
!input.Filter.IsNullOrWhiteSpace(),
u =>
u.DisplayName.Contains(input.Filter)
)
on inv.SationId equals org.Id
join op in _PartyRepo.GetAll()
.WhereIf(
!input.Filter.IsNullOrWhiteSpace(),
u =>
u.JsonName.Contains(input.Filter)
)
on inv.OperatorId equals op.Id
select new SalesInvoiceListingDto
{
Id = inv.Id,
CustomerRefrenceNumber = inv.CustomerRefrenceNumber,
DueDate = inv.DueDate,
InvoiceDate = inv.InvoiceDate,
Invoicenumber = inv.Invoicenumber,
Refrencenumber = inv.Refrencenumber,
StatusId = inv.StatusId,
Operator = op.JsonName,
Station = org.DisplayName,
Customer = inv.CustomerName
};
var desiredItems = query
.OrderByDescending(u => u.InvoiceDate)
.PageBy(input)
.ToList();
var TotalCount = query.Count();
return new PagedResultDto<SalesInvoiceListingDto>(
TotalCount,
desiredItems
);
}
catch (Exception ex)
{
return null;
}
}
i got this error :
A second operation started on this context before a previous operation completed. Any instance members are not guaranteed to be thread safe
when this function Executed
public PagedResultDto<SalesInvoiceListingDto> InvoicesList(FilterDto input)
{
try
{
var query = from inv in _txSalesInfo.GetAll()
// .WhereIf(
// !input.Filter.IsNullOrWhiteSpace(),
// u =>
// u.Invoicenumber.Contains(input.Filter) ||
// u.CustomerName.Contains(input.Filter) ||
// u.Refrencenumber.Contains(input.Filter)
//)
from org in _organizationUnitRepository.GetAll().Where(a => a.Id == inv.SationId)
// .WhereIf(
//!input.Filter.IsNullOrWhiteSpace(),
//u =>
// u.DisplayName.Contains(input.Filter)
// )
from op in _PartyRepo.GetAll().Where(a => a.Id == inv.OperatorId)
// .WhereIf(
//!input.Filter.IsNullOrWhiteSpace(),
// u =>
// u.JsonName.Contains(input.Filter)
// )
select new { inv, op, org };
var items = query
.OrderByDescending(a => a.inv.InvoiceDate)
.PageBy(input)
.ToList();
var projectedItems = (from a in items
select new SalesInvoiceListingDto
{
Id = a.inv.Id,
CustomerRefrenceNumber = a.inv.CustomerRefrenceNumber,
DueDate = a.inv.DueDate,
InvoiceDate = a.inv.InvoiceDate,
Invoicenumber = a.inv.Invoicenumber,
Refrencenumber = a.inv.Refrencenumber,
StatusId = a.inv.StatusId,
Operator = a.op.JsonName,
Station = a.org.DisplayName,
Customer = a.inv.CustomerName
}).ToList();
var TotalCount = query.Count();
return new PagedResultDto<SalesInvoiceListingDto>(
TotalCount,
projectedItems
);
}
catch (Exception ex)
{
return null;
}
}
although i replaced all async to sync
iam facing this issue in my function :
Expression of type 'System.Collections.Generic.IEnumerable1[sagoERP.PartiesDictionary.PartiesDictionaries]' cannot be used for parameter of type 'System.Linq.IQueryable
1[sagoERP.PartiesDictionary.PartiesDictionaries]' of method 'System.Linq.IQueryable1[sagoERP.PartiesDictionary.PartiesDictionaries] WhereIf[PartiesDictionaries](System.Linq.IQueryable
1[sagoERP.PartiesDictionary.PartiesDictionaries], Boolean, System.Linq.Expressions.Expression1[System.Func
2[sagoERP.PartiesDictionary.PartiesDictionaries,System.Boolean]])'
Function
public async Task<PagedResultDto<SalesInvoiceListingDto>> InvoicesList(FilterDto input)
{
try
{
var query = from inv in _txSalesInfo.GetAll().OrderByDescending(a => a.InvoiceDate)
.WhereIf(
!input.Filter.IsNullOrWhiteSpace(),
u =>
u.Invoicenumber.Contains(input.Filter) ||
u.CustomerName.Contains(input.Filter) ||
u.Refrencenumber.Contains(input.Filter)
)
from org in _organizationUnitRepository.GetAll().Where(a => a.Id == inv.SationId)
.WhereIf(
!input.Filter.IsNullOrWhiteSpace(),
u =>
u.DisplayName.Contains(input.Filter)
)
from op in _PartyRepo.GetAll().Where(a => a.Id == inv.OperatorId)
.WhereIf(
!input.Filter.IsNullOrWhiteSpace(),
u =>
u.JsonName.Contains(input.Filter)
)
select new SalesInvoiceListingDto
{
Id = inv.Id,
CustomerRefrenceNumber = inv.CustomerRefrenceNumber,
DueDate = inv.DueDate,
InvoiceDate = inv.InvoiceDate,
Invoicenumber = inv.Invoicenumber,
Refrencenumber = inv.Refrencenumber,
StatusId = inv.StatusId,
Operator = op.JsonName,
Station = org.DisplayName,
Customer = inv.CustomerName
};
var desiredItems = await query
.OrderByDescending(u => u.InvoiceDate)
.PageBy(input)
.ToListAsync();
var TotalCount = await query.CountAsync();
return new PagedResultDto<SalesInvoiceListingDto>(
TotalCount,
desiredItems
);
}
catch (Exception ex)
{
return null;
}
}