Base solution for your next web application

Activities of "evadmin"

Bless you! That was the issue! I need a combination of a default TenantId and strategically placed calls to _unitOfWorkManager.Current.SaveChangesAsync(); to make it work, but the key was that I was creating org units with a null TenantId. Thank you so much! What a great way to kick 2019 off!

Happy New Year! -Gabe

I changed the file to an embedded resource and that solved the problem. Since that was a file that was generated as part of my default project, it never occured to me that I would have to modify it's build properties. Anyway, thanks for the help, glad that's working now :)

That did it! Thank you!

Answer

The problem I encountered is based on some quirks of using smtp.Office365.com. After reading a bit about sending emails with Office365 and MailKit, I solved my problem by replacing DefaultMailKitSmtpBuilderwith a custom one that's exactly the same with the addition of two lines:

client.ServerCertificateValidationCallback = (s, c, h, e) => true; and client.AuthenticationMechanisms.Remove("XOAUTH2");

Here's my complete Office365SmtpBuilder implementation:

public class Office365SmtpBuilder : IMailKitSmtpBuilder
    {
        private readonly ISmtpEmailSenderConfiguration _smtpEmailSenderConfiguration;

        public Office365SmtpBuilder(ISmtpEmailSenderConfiguration smtpEmailSenderConfiguration)
        {
            _smtpEmailSenderConfiguration = smtpEmailSenderConfiguration;
        }

        public virtual SmtpClient Build()
        {
            var client = new SmtpClient();

            try
            {
                ConfigureClient(client);
                return client;
            }
            catch
            {
                client.Dispose();
                throw;
            }
        }

        protected virtual void ConfigureClient(SmtpClient client)
        {
            client.ServerCertificateValidationCallback = (s, c, h, e) => true;  //added this line

            client.Connect(
                _smtpEmailSenderConfiguration.Host,
                _smtpEmailSenderConfiguration.Port,
                _smtpEmailSenderConfiguration.EnableSsl
            );

            client.AuthenticationMechanisms.Remove("XOAUTH2");  //added this line

            var userName = _smtpEmailSenderConfiguration.UserName;
            if (!userName.IsNullOrEmpty())
            {
                client.Authenticate(
                    _smtpEmailSenderConfiguration.UserName,
                    _smtpEmailSenderConfiguration.Password
                );
            }
        }
    }

I replaced the DefaultMailKitSmtpBuilder service by updating my AdminCoreModule in the PreInitialize() method:

if (DebugHelper.IsDebug)
            {
                //Disabling email sending in debug mode
                Configuration.ReplaceService<IMailKitSmtpBuilder, Office365SmtpBuilder>(DependencyLifeStyle.Transient);
            }
Answer

Hi, I'm using the jQuery version. When I navigate away it does not show the correct image. Here are the steps I took:

  • Navigate to /Admin/Settings > Appearance
  • Click "Choose File" (I selected a .png file, in case the extension matters)
  • Click "Upload" (at this point the graphic in the banner changes to look like the one I uploaded)
  • Click "Save All" (I've also tried it without clicking "Save All")
  • Press F5 (at this point the banner graphic reverts back to ASP.NET ZERO)
  • Navigate to /Admin/Dashboard (the graphic is still ASP.NET ZERO)

So I was finally able to make this work with a hack. I'll share what I did in case anyone else runs into trouble.

When accessing protected routes, AuthorizationHelper.AuthorizeAsync() is called:

public async Task AuthorizeAsync(IEnumerable<IAbpAuthorizeAttribute> authorizeAttributes)
        {
            if (!_authConfiguration.IsEnabled)
            {
                return;
            }

            if (!AbpSession.UserId.HasValue)  //this was ALWAYS NULL for me
            {
                throw new AbpAuthorizationException(
                    LocalizationManager.GetString(AbpConsts.LocalizationSourceName, "CurrentUserDidNotLoginToTheApplication")
                    );
            }

            foreach (var authorizeAttribute in authorizeAttributes)
            {
                await PermissionChecker.AuthorizeAsync(authorizeAttribute.RequireAllPermissions, authorizeAttribute.Permissions);
            }
        }

Digging deeper, I found that userIdClaim in ClaimsAbpSession was ALWAYS NULL as well:

public class ClaimsAbpSession : AbpSessionBase, ISingletonDependency
    {
        public override long? UserId
        {
            get
            {
                if (OverridedValue != null)
                {
                    return OverridedValue.UserId;
                }
                
                //userIdClaim is always null because AbpClaimTypes.UserId == "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier";
                var userIdClaim = PrincipalAccessor.Principal?.Claims.FirstOrDefault(c => c.Type == AbpClaimTypes.UserId);
                if (string.IsNullOrEmpty(userIdClaim?.Value))
                {
                    return null;
                }

                long userId;
                if (!long.TryParse(userIdClaim.Value, out userId))
                {
                    return null;
                }

                return userId;
            }
        }

The accessToken returned by IdentityServer4 as a "sub" claim with the UserId value in it, so I simply added

AbpClaimTypes.UserId = "sub";

to Evsuite.Admin.Web.Host.AuthConfigurer.Configure();

Now ClaimsAbpSession.UserId is set to the correct AbpUsers.Id.

Nevermind! I found it in <myproject>.Web.Core\IdentityServer\IdentityServerConfig.cs

Showing 1 to 7 of 7 entries