You can call the
await InvokeAsync(StateHasChanged)after changing theSelectedTenantId. Ensure the input has set the correct value.
I tried that too, but it didn't work. I thought it should work...
What can you tell me about the ReturnUrl?
I found another solution by creating a form around each button.
One more question: what is the purpose of the ReturnUrl? Is it to go to a specific page on the tenant or to return to a specific page when returning to the host?
Neither seems to work.
I found the problem. It works for me with hard-coded values. The problem is that SelectedTenantId and SelectedTenantUserName are set too late and are not included when the form is submitted.
I guess I'll have to write it in via JavaScript, or do you have a better solution?
I just sent you the log file to your email.
Unfortunately, I haven't been able to get it to work yet. I tried three different variations. With the first two, I get the error message: “There is no user with username: admin!” But this user does exist (it also works when I use impersonation in the other way).
I don't see any error messages or other indications in the log file.
The third option is the one suggested above by the AI bot. But there I get a 404 error.
This is the code:
<form method="post" action="Account/ImpersonateTenant" id="ImpersonationForm1">
<input type="hidden" name="TenantId" value="@SelectedTenantId" />
<input type="hidden" name="TenantUserName" value="@SelectedTenantUserName" />
</form>
<form method="post" data-ajaxForm="false" action="Account/ImpersonateTenant" id="ImpersonationForm2">
<AntiforgeryToken />
<input type="hidden" name="ReturntId" value="@SelectedTenantId" />
<input type="hidden" name="TenantUserName" value="@SelectedTenantUserName" />
<input type="hidden" name="ReturnUrl" value="" />
</form>
// Impersonation variant 1
private async Task SubmitImpersonationForm1(Guid tenantId)
{
Logger.Log(LogLevel.Information, "Start impersonation variant 1");
SelectedTenantId = tenantId.ToString();
SelectedTenantUserName = "admin";
await JSRuntime.InvokeVoidAsync("submitForm", "ImpersonationForm1");
}
// Impersonation variant 2
private async Task SubmitImpersonationForm2(Guid tenantId)
{
Logger.Log(LogLevel.Information, "Start impersonation variant 2");
SelectedTenantId = tenantId.ToString();
SelectedTenantUserName = "admin";
var tokens = Antiforgery.GetAndStoreTokens(HttpContextAccessor.HttpContext);
var requestToken = tokens.RequestToken;
await JSRuntime.InvokeVoidAsync("submitFormWithAntiforgeryToken", "ImpersonationForm2", $"/Account/ImpersonateTenant", requestToken);
}
// Impersonation variant 3
private async Task SubmitImpersonationForm3(Guid tenantId)
{
Logger.Log(LogLevel.Information, "Start impersonation variant 3");
//var response = await Http.PostAsJsonAsync("/api/account/impersonation/tenant", new { tenantId });
var response = await Http.PostAsJsonAsync("https://localhost:44367/api/account/impersonation/tenant", new { tenantId });
if (response.IsSuccessStatusCode)
{
//var result = await response.Content.ReadFromJsonAsync<ImpersonateResultDto>();
//NavigationManager.NavigateTo(result.ImpersonationUrl, forceLoad: true);
}
}
function submitForm(formName) {
var form = document.getElementById(formName);
form.submit();
}
function submitFormWithAntiforgeryToken(formName, uri, requestToken) {
var form = document.getElementById(formName);
// Check if the antiforgery token is present in the form, if the token is not present, create a new hidden input field for the token
var tokenInput = form.querySelector('input[name=__RequestVerificationToken]');
if (!tokenInput) {
{
tokenInput = document.createElement('input');
tokenInput.type = 'hidden';
tokenInput.name = '__RequestVerificationToken';
form.appendChild(tokenInput);
}
}
// Set the value of the token
tokenInput.value = requestToken;
// Update the form's action with the new URI and submit the form
form.action = uri;
form.submit();
}
Any ideas?
I mean something like this:
await AccountAppService.ImpersonateTenantAsync()
Is this possible?
Is there no way to call up a corresponding service method from the SaaS module directly from my AppService?
Ok, now the breakpoint works inside of AddAbpCookieConsent
At first, however, nothing appeared on the website (just an empty AbpCookieConsent widget).
Btw, you should also add app.UseAbpCookieConsent() in your request pipeline.
To add app.UseAbpCookieConsent() in the OnApplicationInitialization method makes the difference. This is very important. And the order is also very important. I had it at the end first, but that didn't work. Now I have it after app.UseAuthentication(); and then it works.
Some very important information that I think is missing in the documentation. Please add them so that others don't stumble across the same errors.
Thank you @EngincanV for your help.
Yes, this is the correct package to add to your public web project. If the cookie consent still doesn't appear, it's possible that there's an entry in your localStorage with the value set to 'dismiss'. Please check your localStorage, clear it if possible, and try again to see if the consent banner is displayed.
Clearing the local storage cache did not help...
That's my code:
I set a breakpoint on line 115, but never get there.