Base solution for your next web application

Activities of "enio"

We have succesfully integrated DevExpress Dashboard in our AspNetZero 6.7.0.0, .net core, angular 8 solution. This is a great feature and the dashboard/reporting is working perfectly.

However now we would like to secure the access to the dashboard therefore we wanted to check the users identity provided in the HttpContext. But unfortunately the identity is always empty/not set:

public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            //MVC
            services.AddMvc(options =>
            {
                options.Filters.Add(new CorsAuthorizationFilterFactory(DefaultCorsPolicyName));
            })
                .SetCompatibilityVersion(CompatibilityVersion.Version_2_2)
                .AddDefaultDashboardController((configurator, serviceProvider) =>
                {
                    IHttpContextAccessor httpContextAccessor = (IHttpContextAccessor)serviceProvider.GetService(typeof(IHttpContextAccessor));
                    HttpContext context = httpContextAccessor.HttpContext;
                    var userIdentity = context.User.Identity;      <-- userIdentity.Name is null !!
                    ...

I guess the problem is that the Dashboards' Controller does now nothing about AspNetZero's authentication/authorization and therefore does not provide the information that I need. Is there a way that I can find out the current users Id?

Hi Velu, although this post is now closed I hope that you still receive my request. Could you please send some sample code to [email protected]?

This is the Context: https://download.enio.ch/PEPDVPXM/web_managerDbContext.cs ..it's actually the original AspNetZero context

This is our repository:

public class InvoiceRIrTaskRepository : web_managerRepositoryBase<IrTask>, IInvoiceRIrTaskRepository
{
    public InvoiceRIrTaskRepository(IDbContextProvider<web_managerDbContext> dbContextProvider) : base(dbContextProvider)
    {
    }

    public async Task UpdateIrTaskGraph(IrTask task)
    {
        task.IrCase.Documents = new List<Document>();

        Context.Update(task);
        Context.SaveChanges();
    }
}

This is our repositories interface:

public interface IInvoiceRIrTaskRepository : IRepository<IrTask>
{
    Task UpdateIrTaskGraph(IrTask task);
}

And this is the base repository - actually the original file as we found it in AspNetZero 6.7

    /// <summary>
    /// Base class for custom repositories of the application.
    /// </summary>
    /// <typeparam name="TEntity">Entity type</typeparam>
    /// <typeparam name="TPrimaryKey">Primary key type of the entity</typeparam>
    public abstract class web_managerRepositoryBase<TEntity, TPrimaryKey> : EfCoreRepositoryBase<web_managerDbContext, TEntity, TPrimaryKey>
        where TEntity : class, IEntity<TPrimaryKey>
    {
        protected web_managerRepositoryBase(IDbContextProvider<web_managerDbContext> dbContextProvider)
            : base(dbContextProvider)
        {

        }

        //add your common methods for all repositories
    }

    /// <summary>
    /// Base class for custom repositories of the application.
    /// This is a shortcut of <see cref="web_managerRepositoryBase{TEntity,TPrimaryKey}"/> for <see cref="int"/> primary key.
    /// </summary>
    /// <typeparam name="TEntity">Entity type</typeparam>
    public abstract class web_managerRepositoryBase<TEntity> : web_managerRepositoryBase<TEntity, int>
        where TEntity : class, IEntity<int>
    {
        protected web_managerRepositoryBase(IDbContextProvider<web_managerDbContext> dbContextProvider)
            : base(dbContextProvider)
        {

        }

        //do not add any method here, add to the class above (since this inherits it)!!!
    }

The context I am using is comming from the base class EfCoreRepositoryBase and provided to this base class in the base call of my constructor. My constructor gets the context injected:

IDbContextProvider&lt;web_managerDbContext> dbContextProvider

Yes the change is audited. The concerning entity class has the [Audited]-annotation on class level and the class is listed in EntityHistoryHelper. When I update the entity with the default abp IRepository<myEntity> everything is working just fine. But as soon as I update the entity with the context from my custom repository the changed entities are not detected / not listed in the AbpEntityPropertyChanges table.

In order to update an entity object including child object properties we have created a custom repository and are using the Update-Method directly on the EF-Context. But when we update the entities like this we don't have any entries in the AbpEntityPropertyChanges table. However we do have a new entry in AbpEntityChanges. Is there a simple way to fix this issue or is is meanwhile fixed - we are on version 6.7 from last february.

Do we have to implement IEntityHistoryStore in our custom repository - if yes could you please provide a simple example?

As stated in the this issue we do have the possibility to pass custom values to the initial GetAll by providing an implementation of ICustomConfigProvider. My question is how can I load some data from the database within such an implementation? Obviously DI is not working at this part of the application :-(

My understanding of the ^8.0.0 pattern is that npm/yarn will install the latest version with 8.x.x. Therefore in my scenario the problem suddenly occured when angular has published version 8.1. So my build automatically switched to 8.1. My solution was simple - I have just changed all angular related entries in package.json from ^8.0.0 to ~8.0.0. In my opinion this pattern represents 8.0.x - therefore the angular version was nailed down to 8.0 and not switching to the problematic 8.1 version.

I found the answer elsewhere in the forum - our users in the ActiveDirectory don't have an email adress set:

https://support.aspnetzero.com/QA/Questions/6180#answer-2ce4d101-ea8a-5387-f188-39eade0e077c

AND

https://support.aspnetzero.com/QA/Questions/3121#answer-2c69c3d0-fab5-479a-8189-01157bfbaa5d

I have enabled LDAP authentication in code and afterwards on the settings page.

When I try to login with a non existing AD-User or take a wrong password I get the correct not authorized error message. However if I use an existing AD-username and correct password I get the following exception:

ERROR 2019-07-24 17:24:18,800 [82 ] Mvc.ExceptionHandling.AbpExceptionFilter - Object reference not set to an instance of an object. System.NullReferenceException: Object reference not set to an instance of an object. at Abp.Authorization.Users.AbpUser1.SetNormalizedNames() at Abp.Authorization.AbpLogInManager3.TryLoginFromExternalAuthenticationSources(String userNameOrEmailAddress, String plainPassword, TTenant tenant) at Abp.Authorization.AbpLogInManager3.LoginAsyncInternal(String userNameOrEmailAddress, String plainPassword, String tenancyName, Boolean shouldLockout) at Abp.Authorization.AbpLogInManager3.LoginAsync(String userNameOrEmailAddress, String plainPassword, String tenancyName, Boolean shouldLockout) at Abp.Threading.InternalAsyncHelper.AwaitTaskWithPostActionAndFinallyAndGetResult[T](Task1 actualReturnValue, Func1 postAction, Action`1 finalAction) at web_manager.Web.Controllers.TokenAuthController.GetLoginResultAsync(String usernameOrEmailAddress, String password, String tenancyName) in /home/vsts/work/1/s/src/web_manager.Web.Core/Controllers/TokenAuthController.cs:line 590 at web_manager.Web.Controllers.TokenAuthController.Authenticate(AuthenticateModel model) in /home/vsts/work/1/s/src/web_manager.Web.Core/Controllers/TokenAuthController.cs:line 112 at lambda_method(Closure , Object ) at Microsoft.AspNetCore.Mvc.Internal.ActionMethodExecutor.AwaitableObjectResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments) at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeActionMethodAsync() at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeNextActionFilterAsync() at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ActionExecutedContext context) at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted) at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeInnerFilterAsync() at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeNextExceptionFilterAsync()

Can you please point me the direction where I should search for a solution? As I get the exception message above only with correct login credentials I guess that ABP successfully communicated with the AD.

kind regards, marco

@maliming thank you for the hint with downgrading to ng 8.0.x. It is working now for me. But this can't be the solution for the long run.

Could you please post into this thread once there is a solution for higher angular versions?

Showing 11 to 20 of 24 entries