Thanks for the response; I have since relealised that I had not iimplemented this correctly.
.net core MVC 9.x
I have the following code with my ZeroDbContext:
`
protected virtual long[] GetCurrentUserOrganizationUnitIds()
{
var userOuClaim = PrincipalAccessor.Principal?.Claims.FirstOrDefault(c => c.Type == ClaimsConstants.OrganizationUnitClaimKey);
if (string.IsNullOrEmpty(userOuClaim?.Value))
{
return Array.Empty<long>();
}
return userOuClaim.Value.Split(',', StringSplitOptions.RemoveEmptyEntries)
.Select(long.Parse)
.ToArray();
}
protected override Expression<Func<TEntity, bool>> CreateFilterExpression<TEntity>()
{
var expression = base.CreateFilterExpression<TEntity>();
if (typeof(OrganizationUnit).IsAssignableFrom(typeof(TEntity)))
{
if (IsOrganizationUnitFilterEnabled)
{
Expression<Func<TEntity, bool>> organizationUnitFilter = e => CurrentOUId.Contains(((IEntity<long>) e).Id);
expression = expression == null ? organizationUnitFilter : CombineExpressions(expression, organizationUnitFilter);
}
}
return expression;
}
`
The problem I have is that PrincipalAccessor.Principal?.Claims.FirstOrDefault(c => c.Type == ClaimsConstants.OrganizationUnitClaimKey);
always returns null.
My working assumption is that filters are created only once when the context is first instantiated and there is no Principal at that time.
I believe other values used within the ZeroDbContext such as CurrentTenantId are provided to the context from the AbpSession.
Question How can I add an EF filter that is based on data that is within the PrincipalAccessor.Principal at the time the query is executed?
.net core MVC 9.x
I am looking for some assistance with a problem I have with creating a new claim on a ClaimPrincipal. As a quick background to what I am doing, we are enhancing the organization unit (OU) functionality in such a way that a user can only access OUs that they belong to. I have followed this guide: https://aspnetboilerplate.com/Pages/Documents/Articles\How-To\add-custom-data-filter-ef-core
However the guide assumes that a User HAS an OU, not is IN one or many OUs.
It is no problem to modifying the the UserClaimsPrincipalFactory::CreateAsync method to add a claim to describe the ID's of the OUs, but the problem I am having is ensuring the the User record that is passed in has the OrganizationUnits collection hydrated. If the user is not hydrated, I cannot add the claim.
I can of course load the OU's for that current user each time the CreateAsync method is called, but it seems unnecessary making an extra request to the database.
I would prefer to intercept the Repository in the UserStore and add an 'include' somewhere central.
The only way I have been able to do this is to override all the 'Find' methods in the UserStore and add in the include statement. This seems really rubbish.
Does anyone have any suggestions?
I notice that aspnetzero v10 rc-1 is build on .net 5. This raises a couple of questions:
If I understand correctly from Microsoft, full consilidation of the .net frameworks is not due until the end of next year with .net 5.
Version: 6.7, dotnet core, MVC and jQuery, multi-tenant.
I have been tasked with setting up Google and Microsoft sign-in providers with our instance of ASPNETZERO. The set up of the Google sign-in was almost trivial and we had it running in probably less than an hour. However, I have spent at 9 hours+ trying to get OpenID working with no success.
I set up the OpenID client ID in our Azuze Portal and I used the test solution found here : https://github.com/Azure-Samples/active-directory-aspnetcore-webapp-openidconnect-v2/archive/aspnetcore2-2.zip
I ran the test solution locally and everything worked ok.
But I am unable to get this working with ASPNETZERO.
I have tried numerous combination of settings, tenantID, return urls etc and the most I can get is an error coming back from the MS login that says:
https://login.live.com/err.srf?lc=2057#error=invalid_request&error_description=The+provided+value+for+the+input+parameter+'redirect_uri'+is+not+valid.+The+expected+value+is+a+URI+which+matches+a+redirect+URI+registered+for+this+client+application.
"The provided value for the input parameter 'redirect_uri' is not valid. The expected value is a URI which matches a redirect URI registered for this client application."
I would really appreciate if anyone else could share their experiences with logging into ASPZNETZERO with a Microsoft account.
Thank you in advance.
Upgrading Visual Studio fixed the issue, thank you.
I am currently running 15.7.3; today I will update to 15.9.5 and see if that resolves the issue.
Further to the issue I raised yesterday.
When I created a fresh new ASP NET CORE 2.2 web project within Visual Studio, no aspNetCore module is explicitly set and the project does run in IIS Express successfully.
I have upgraded to Zero v6.5 MVC. I have upgraded the ASP CORE SDK and Web hosting bundle to v2.2.1.
However when I host the web project from within Visual Studio in IIS Express, the following error occurs:
HTTP Error 500.21 - Internal Server Error Handler "aspNetCore" has a bad module "AspNetCoreModuleV2" in its module list
From within the web.config for the MVC project if I change the aspNetCore module to AspNetCoreModule rather than AspNetCoreModuleV2 then I am able to debug. However I am concerned this is a work around and not a fix.
Has anyone else experienced this issue?
It would seem that WIndows Defender is inaccurately flagging the dll as a threat. I can see from your results that this is not the case. I have also asked a colleage to scan the file and he has not reported the issue. I am happy to close this ticket.