Base solution for your next web application
Starts in:
01 DAYS
01 HRS
01 MIN
01 SEC

Activities of "carelearning"

@ismcagdas,

Sorry for the late reply. Yes we are using multitenancy. Our work-around is okay we just questioned why we need to override the base class method GetRoleByNameAsync.

        public virtual async Task<TRole> GetRoleByNameAsync(string roleName)
            {
                var role = await FindByNameAsync(roleName);
                if (role == null)
                {
                    throw new AbpException("There is no role with name: " + roleName);
                }

                return role;
            }

with

    public override async Task<Role> GetRoleByNameAsync(string roleName)
    {
        return await Task.FromResult(_roleRepository
            .GetAll()
            .SingleOrDefault(x => String.Equals(x.Name, roleName)));
    }

Dear @musa.demir,

Thank your for the reply. While developing this feature I manually added the Administrator role using the SQL Server Mangement Studio Edit Table feature. When I script the data from that table here is that record.

  SET IDENTITY_INSERT [dbo].[AbpRoles] ON 
  INSERT [dbo].[AbpRoles] ([Id], [TenantId], [Name], [DisplayName], [IsStatic], [IsDefault], [IsDeleted], [DeleterUserId], [DeletionTime], [LastModificationTime], [LastModifierUserId], [CreationTime], [CreatorUserId], [NormalizedName]) VALUES (1, 1, N'Administrator', N'Administrator', 1, 1, 0, NULL, NULL, NULL, NULL, CAST(N'2021-01-13T19:01:23.653' AS DateTime), NULL, N'ADMINISTRATOR')
  SET IDENTITY_INSERT [dbo].[AbpRoles] OFF

I have since added the framework code, previously commented out by us, from the Entity Framework csproject for TenantDb seeding. That code looks like this:

  // Administrator role
  var adminRole = _context.Roles.FirstOrDefault(r => r.TenantId == _tenantId && r.Name == StaticRoleNames.Tenants.Administrator);
            if (adminRole == null)
            {
                _context.Roles.Add(new Role(_tenantId, StaticRoleNames.Tenants.Administrator, StaticRoleNames.Tenants.Administrator) { IsStatic = true, IsDefault = true });
                _context.SaveChanges();
            }

I did alter the constant value from 'Admin' to 'Administrator'; here is that adjustment:

      public static class Tenants
      {
          public const string Administrator = "Administrator";

          public const string User = "User";
      }

To assign I picked a known user and again used the SQL Management Studio Edit Table feature to populate the table data. In this instance the TenantId was 1, the UserId was 1 and the RoleId was 1 and the CreationTime was now. The equivalent T-SQL code to insert the record would like this:

     INSERT INTO AbpUserRoles (TenantId, UserId, RoleId, CreationTime) VALUES (1, 1, 1, GetUtcDate());

Hi Zony,

Thank you very much for your reply. This will work for some use cases, but not the one we have. We have a situation where multiple settings could be added and/or updated for a certain Tenant. Is there any API or process to reload all of the settings? Thank you again.

Thank you for your response. Since we are using the "L()" method, it appears that I would have to create my own LocalizationSource.GetString(name, args) this is in LocalizationSourceExtensions.cs. Do I create another version of LocalizationSourceExtensions as well? or can I create that in my own NullLocalizationSource.cs? Or is this a better way?

Thanks again for your help.

We worked around the issue by extracting functionality into two separate hub classes and registered them independently.

We changed our IOC registrations in AbpZeroTemplateWebModule in PreInitialize from:

Old Way

  IocManager.IocContainer.Register(
        Component.For<IMessage<string>, IStatusMessage>()
            .ImplementedBy<ManagementHub>()
            .LifestyleSingleton()
  );

New Way

  IocManager.Register<IMessage, ManagementHub>();
  IocManager.Register<IStatusMessage, AgentHub>();

The AgentHub's OnConnected and OnDisconnected is not firing, however the ManagementHub now is. This works for our needs.

Dear @ismcagdas ,

We were able to narrow down the error to the IAbpZeroDbMigrator.CreateOrMigrateForHost(); call.

However we were able to get the new tooling working by replacing migrate with ef6 with the following code.

EF 6.2.0 (old)
migrate.exe "MyCompanyName.AbpZeroTemplate.EntityFramework.dll" /StartUpDirectory=.\ MyCompanyName.AbpZeroTemplate.AbpZeroTemplateHost.Configuration /startupConfigurationFile="../web.config"
EF 6.3.0+ (new)
ef6.exe database update --assembly "MyCompanyName.AbpZeroTemplate.EntityFramework.dll" --migrations-config "MyCompanyName.AbpZeroTemplate.AbpZeroTemplateHost.Configuration" --config "../web.config"

Thank you for your time and energy.

Dear @Aaron,

Thanks. We were able to apply the workaround with the following code:

WebClientInfoProviderHack.cs

namespace MyCompanyName.AbpZeroTemplate.Web.Hacks
{
    using Abp.Auditing;
    using System;
    using System.Net;
    using System.Net.Sockets;
    using System.Web;

    public class WebClientInfoProviderHack : WebClientInfoProvider
    {
        protected override string GetClientIpAddress()
        {
            var httpContext = HttpContext.Current;
            if (httpContext?.Request.ServerVariables == null)
                return null;

            var clientIp = httpContext.Request.ServerVariables["HTTP_X_FORWARDED_FOR"] ??
                           httpContext.Request.ServerVariables["REMOTE_ADDR"];

            // Remove port if present
            clientIp = clientIp.Contains(":") ? clientIp.Remove(clientIp.IndexOf(':')) : clientIp;

            try
            {
                foreach (var hostAddress in Dns.GetHostAddresses(clientIp))
                    if (hostAddress.AddressFamily == AddressFamily.InterNetwork)
                        return hostAddress.ToString();

                foreach (var hostAddress in Dns.GetHostAddresses(Dns.GetHostName()))
                    if (hostAddress.AddressFamily == AddressFamily.InterNetwork)
                        return hostAddress.ToString();
            }
            catch (Exception ex)
            {
                Logger.Debug(ex.ToString());
            }

            return clientIp;
        }

    }
}

AbpZeroTemplateWebModule.cs

public override void PreInitialize()
        {
            // elided code here
            Configuration.ReplaceService<IClientInfoProvider, WebClientInfoProviderHack>();
        }

Dear @ismcagdas

We were migrating from this commit be0fc34b5c270a9743a9ad830ebed0f5e4dc24ba which is targeting Abp 4.11.0. Is this information you need?

Dear Support, It has been 9 days since we have last heard from you. We added our stack information when requested and was just checking in to see if there is any update on this or if anymore information is needed. Thank you,

Thank you.

Showing 1 to 10 of 65 entries