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

Activities of "mightyit"

@justinp Clear the domain name field

@rnguyen Clear the domain name field

Have you looked at SqlBulkCopy for doing high-performance bulk inserts?

https://docs.microsoft.com/en-us/dotnet/api/system.data.sqlclient.sqlbulkcopy?view=netframework-4.8

I was able to figure out what the issue was.

I was calling ImpersonatedAuthenticate with an HttpClient for which the bearer token was already set (by calling _httpClient.SetBearerToken(bearerToken);) during authentication. It seems that, if the bearertoken is set for your call, it will resolve the AbpSession.TenantId to the tenantid to which the bearer token applied.

The fix was to new up the HttpClient, so that there is no bearer token set on the subsequent call to ``ImpersonatedAuthenticate`.

Yes, AbpSession.TenantId remains null, even though the Abp.TenantId request header was set to 2.

Here is the session object, serialized as JSON:

{
  "UserId": 1,
  "TenantId": null,
  "ImpersonatorUserId": null,
  "ImpersonatorTenantId": null,
  "MultiTenancy": {
    "IsEnabled": true,
    "IgnoreFeatureCheckForHostUsers": false,
    "Resolvers": [
      "Abp.AspNetCore.MultiTenancy.DomainTenantResolveContributor, Abp.AspNetCore, Version=4.5.0.0, Culture=neutral, PublicKeyToken=null",
      "Abp.AspNetCore.MultiTenancy.HttpHeaderTenantResolveContributor, Abp.AspNetCore, Version=4.5.0.0, Culture=neutral, PublicKeyToken=null",
      "Abp.AspNetCore.MultiTenancy.HttpCookieTenantResolveContributor, Abp.AspNetCore, Version=4.5.0.0, Culture=neutral, PublicKeyToken=null"
    ],
    "TenantIdResolveKey": "Abp.TenantId"
  },
  "MultiTenancySide": 2
}

Here is the request.Headers object, serialized as JSON:

{
  "Connection": [
    "Keep-Alive"
  ],
  "Content-Type": [
    "application/json; charset=utf-8"
  ],
  "Accept": [
    "application/json"
  ],
  "Authorization": [
    "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxIiwibmFtZSI6ImFkbWluIiwiQXNwTmV0LklkZW50aXR5LlNlY3VyaXR5U3RhbXAiOiJRNUpOWlg2NEg0QlZEV1pFVTVCV0hST1QyVzc3UEg1MyIsInJvbGUiOiJBZG1pbiIsImp0aSI6IjJkNmE1YWRmLTVlYjYtNGU3Yy05OTA3LTExZDk3NzFkNjgwZCIsImlhdCI6MTU2NTc2OTY3MywidG9rZW5fdmFsaWRpdHlfa2V5IjoiOGQyNDVhYzctZGM1MC00ZmU1LWEwMzgtNWJjMWIwN2Q1NjM4IiwidXNlcl9pZGVudGlmaWVyIjoiMSIsIm5iZiI6MTU2NTc2OTY3MywiZXhwIjoxNTY1ODU2MDczLCJpc3MiOiJaZW5EZXRlY3QiLCJhdWQiOiJaZW5EZXRlY3QifQ.LG1lcqgRpjmG_Gmh13zwbj-nqejDNAtij5b9HKeU_60"
  ],
  "Host": [
    "localhost:62114"
  ],
  "Content-Length": [
    "0"
  ],
  "Abp.TenantId": [
    "2"
  ],
  "MS-ASPNETCORE-TOKEN": [
    "359ecd4d-4df5-46bd-95b3-630aae1dddbb"
  ],
  "X-Original-Proto": [
    "http"
  ],
  "X-Original-For": [
    "127.0.0.1:58003"
  ]
}

@ismcagdas @ryancyq

See below screenshot which confirms that the Abp.TenantId header is set correctly.

Also, confirming that setting the Abp.TenantId header does not update AbpSession.TenantId, and thus causes the CheckCurrentTenant check to fail and throw the mentioned exception.

So what would cause the AbpSession.TenantId update to fail?

Yes, but I'm not sure whether I am doing it right. Here is the code I am using for this just before calling tokenAuthClient.ImpersonatedAuthenticateAsync (and still getting the same error as mentioned above):

_httpClient.DefaultRequestHeaders.Remove("Abp.TenantId");
_httpClient.DefaultRequestHeaders.Add("Abp.TenantId",selectedTenantId.ToString());

I have also tried to modify the header for the HttpRequestMessage inside the generated client as follows,with the same outcome:

request_.Headers.Remove("Abp.TenantId");
request_.Headers.Add("Abp.TenantId", selectedTenantId?.ToString());

@ryancyq The provided link gives a 404 error

Swashbuckle depends on ApiExplorer, and the use of the ApiExplorer attribute limits us to specifying only a single groupname per controller / action. As per @ryancyq above, "service proxies are generated via NSwag for angular project." and it seems that during this process a dependency is broken.

The workaround was to create my own attribute for delimiting one-or-more groupnames for an appservice controller or action, and subsequently use reflection in my DocInclusionPredicateFunction to retrieve the groupnames for an action or its containing controller.

[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = true)]
public class SwaggerDocAttribute: Attribute
{
    public SwaggerDocAttribute(params string[] includeInDocuments)
    {
        IncludeInDocuments = includeInDocuments;
    }

    public string[] IncludeInDocuments { get; }
}

options.DocInclusionPredicate((docName, apiDesc) =>
{
    if (!apiDesc.ActionDescriptor.IsControllerAction())
    {
        return false;
    }

    apiDesc.TryGetMethodInfo(out MethodInfo methodInfo);

    var actionDocs = methodInfo.GetCustomAttributes<SwaggerDocAttribute>()
        .SelectMany(a => a.IncludeInDocuments);

    var controllerDocs = methodInfo.DeclaringType.GetCustomAttributes<SwaggerDocAttribute>()
        .SelectMany(a => a.IncludeInDocuments);

    switch (docName)
    {
        case "HostApiv1":
            return apiDesc.GroupName == null || 
            actionDocs.Contains("HostApiv1") || 
            controllerDocs.Contains("HostApiv1");
        case "TenantApiv1":
            return apiDesc.GroupName == null ||
            actionDocs.Contains("TenantApiv1") || 
            controllerDocs.Contains("TenantApiv1");
        default:
            return true;
    }
});

Usage

[DisableAuditing]
[AbpAuthorize(AppPermissions.HostSpecific.Dashboard.Access)]
//[ApiExplorerSettings(GroupName = "HostApiv1")]
[SwaggerDoc("HostApiv1")]
public class HostDashboardAppService : ZenDetectAppServiceBase, IHostDashboardAppService
{
        //...
}

@ryancyq @ismcagdas That works insofar my swagger documentation is concerned, however, it now seems that whenever an app service is decorated with either [ApiExplorerSettings(GroupName = "HostApiv1")] or [ApiExplorerSettings(GroupName = "TenantApiv1")], my client side dependencies on those services are broken. It seems that somehow AbpServiceProxies has a dependency on Swagger generation?

See below:

Showing 11 to 20 of 49 entries