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

Activities of "maharatha"

Thank You Hikalkan. You are a savior 8-) . I will be storing the connection string in a DB table and will be getting the connection string from the table and storing in claims,. As the connection string will keep getting added so not sure if I can store that in a static class using dictionary and it would be one connection string per tenant or user. Correct me if I am wrong in my approach ? I am learning a lot of Aspnet Boiler and wants to keep learning.

Secondly I could access the Abpsession using constructor injection but couldn't use it as I wanted the TenantID to be passed as a parameter to GetDynamicConnectionString() which i couldn't. Also I couldn't use the AbpSession.TenantID inside GetDynamicConnectionString() as it's called before the contructor

Lastly, I am unable to find out one common place where I should add my claims because the connection string would change when the host will impersonate. I was trying in AccountController.cs in SaveImpersonationTokenAndGetTargetUrl method for adding and updating claims but when an user impersonates he impersonates as another user. So the claims for impersonated user is null. Basically where should I set claims for impersonated user.

Thanks in advance.

I am now using Claims to store the connection string and using it this way :

public TesTrans(string nameOrConnectionString): base(GetDynamicConnectionString()) { }

    public static string GetDynamicConnectionString()
    {
        var claimsPrincipal = Thread.CurrentPrincipal as ClaimsPrincipal;
        if (claimsPrincipal == null)
        {
            return null;
        }


        var claimsIdentity = claimsPrincipal.Identity as ClaimsIdentity;

        if (claimsIdentity == null)
        {
            return null;
        }

        var ConnStringClaim = claimsIdentity.Claims.FirstOrDefault(c => c.Type == "ConnString");
        if (ConnStringClaim == null || string.IsNullOrEmpty(ConnStringClaim.Value))
        {
            return null;
        }

        return ConnStringClaim.Value;
    }

in my DBContext.

Is this the right way of approach and is there a cleaner and better approach ?

Thank You for the response. Yes if OU are extended more in ASPNET Zero I am sure it would be helpful for everyone in the community.

Also I was trying to get the TenantID inside my DBContext constructor and it was coming as Null. But as far as I know you should be able to get AbpSession.TenantID values if you are using AspnetZero which I am currently using.

Any help is really appreciated.

Awesome !! Worked for me.

I am currently starting a new project so such quick response is very much appreciated.

Thank You Again .

This is how I am adding claims :

var identity = await UserManager.CreateIdentityAsync(GetCurrentUser(), DefaultAuthenticationTypes.ApplicationCookie);

identity.AddClaim(new Claim("OrganizationId", "2"));

This is how I am trying to get the claim :

public class MyAppSession : IdentityFrameworkClaimsAbpSession {

    // Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType
    private readonly UserManager _userManager;

    public MyAppSession(UserManager userManager, IMultiTenancyConfig multiTenancy) : base(multiTenancy)
    {
        
        _userManager = userManager;
    }

   
    public static long? OrganizationId
    {
        get
        {

            
            var claimsPrincipal = Thread.CurrentPrincipal as ClaimsPrincipal;
            if (claimsPrincipal == null)
            {
                return null;
            }

            var claimsIdentity = claimsPrincipal.Identity as ClaimsIdentity;
            if (claimsIdentity == null)
            {
                return null;
            }
            
            var OrgIdClaim = claimsIdentity.Claims.FirstOrDefault(c => c.Type == "OrganizationId");
            if (OrgIdClaim == null || string.IsNullOrEmpty(OrgIdClaim.Value))
            {
                return null;
            }

            long orgId;
            if (!long.TryParse(OrgIdClaim.Value, out orgId))
            {
                return null;
            }

            return orgId;
        }
      
    }



    
}

I am unable to get the claim :

Am I doing anything wrong ?

Showing 201 to 206 of 206 entries