Base solution for your next web application
Open Closed

Host admin lost permissions after switch account #9104


User avatar
0
Romka created

Hello,

I write in this post because we have the very same problem than this one, and we can't figure out what to do to fix (I initally wrote in the other thread but it did'nt reopen it, that's why I create a new one) ====> https://support.aspnetzero.com/QA/Questions/8956/Can't-see-Tenants-and-Settings-in-admin-console

=> I login as a tenant's user => I "switch back to my account" which is the host admin => I can only see the Administration menu (we removed the Demo ui Components).

It does not occurs each time. When it occurs, if I put a breakpoint, say, in the getCurrentLoginInformations method, I can see that the current user is the right one (UserId 1, TenantId null). If I execute in the immediate window this.PermissionChecker.IsGranted(xxxxx.Authorization.AppPermissions.Pages_Tenants), it returns false.

Any idea on this ?


21 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @romka,

    1. Could you share your AspNet Zero version ?
    2. Do you use Angular or jQuery version ?
    3. Do you have a sense of a specific thing when this problem happens ? For example, does it happen when you wait for a long time or something like that ? This might help us to understand the cause of the problem.

    Thanks,

  • User Avatar
    0
    Romka created

    AspNet Zero v8.8.0 (we first noticed this behavior with the 8.7 version, and maybe before), with Angular. No, long time does'nt seeme to be in account (not sure...). By writing this, I cannot reproduce it. But I encountered that yesterday and my colleagues also noticed the problem on their own environments (with other installations of our applications, and various windows editions).

    When it happens :

    • permissions are still missing after CTL+F5, after empty cache / cookies / hard reload, after logout/login.
    • if we restart the application / IIS, permission are "back" (so it's not a user error or someone who removed the permissions).

    EDIT : it just happened again. maybe you are finally right : I did not touched the application for several hours (but it was running and the page was open in Chrome).

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    Do you use latest version of ABP NuGet packages ? If so, is it possible to share your project via email for us to analyze ?

    Thanks,

  • User Avatar
    0
    Romka created

    Yes, we use latest ABP packages. I send you our code. We have intensively modified the template project and in order to be able to start it, you would need a lot of third-party / corporate projects, it would be several Go of data. So I send you only the corresponding aspnetzero projects, ask me if you need more.

  • User Avatar
    0
    Romka created

    Hello,

    have you received my email ?

    Just to inform you, I've just encountered the problem and the application was started 2 minutes before, so it's not a matter of long time etc. I started the application, navigated to it ; I was already logged in as an impersonated tenant user ; immediately "switch back to my account" to the host admin and the permissions for some pages like Tenants were not there. Then I stopped the application in IIS, restarted it, went back to my browser, F5 : the "tenants" menu appeared.

  • User Avatar
    0
    Romka created

    I can add one info : it's definitively related to the bckend (no cookie or local storage problem) :

    • I encounter the issue using Chrome
      • I open Firefox (just downloaded it, never used it before on this computer), I navigate to the application and the problem is there also.
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @romka

    I open Firefox (just downloaded it, never used it before on this computer), I navigate to the application and the problem is there also.

    Do you mean your existing app or a brand new AspNet Zero applicaiton ?

  • User Avatar
    0
    Romka created

    My existing app, the part "i just downloaded it" refers to Firefox, to say that the browser was not corrupted with any cookie / cache stuff

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @romka,

    Thanks, we are working on your and will get back to you when we find the problem.

  • User Avatar
    0
    Romka created

    Hello,

    any clue on this ?

    We are about to deliver our application to clients next week. We really need this to work as expected...

    Maybe this issue is related ? https://support.aspnetzero.com/QA/Questions/9073/Issue-with-retrieving-Permissions-tenant-specific-permissions-from-the-database-for-a-given-tenant

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @romka,

    We have investigated your source code but couldn't identify a problem. Since, we can't run the project and don't know how to reproduce it, it is hard to detect the problem.

    You can try these;

    1. If you are not using AspNet Zero's latest version, you can download latest version using your project name and compare two projects using a tool like WinMerge.
    2. You can also try to upgrade your ABP NuGet packages to latest version.
  • User Avatar
    0
    OCAPI created

    Hi folks,

    We've just started a new Angular-based project using v 9.0.1 and we've encountered this (or something very similar) too. A reliable way to reproduce the problem is as follows:

    Startup the Angular project and the host project as normal Log in to the host as your admin user Use the "Tenants" menu to log in to one of the tenants Restart the host project only Once it's restarted, use the "Back to my account" option. Host-specific menu items are missing. Restarting the app and then refreshing the browser fixes it.

    Hope that's useful!

    Cheers,

    Simon

  • User Avatar
    0
    Romka created

    Thanks Simon for this feedback.

    From our side it's still not resolved. I don't know if the aspnetzero team has found something.

    Maybe your comment will help them to reproduce ?

  • User Avatar
    0
    OCAPI created

    Hi @Romka,

    I hit this again the other day so looked into it a bit more, and determined that running a Redis instance will prevent the problem. Easiest way on Win10 is to run it under WSL2/Docker:

    docker run -p 6379:6379 -d --rm --name abp-redis redis docker run -p 8080:63790 -d --rm --name redis-stat --link abp-redis:redis insready/redis-stat --server redis

    (The 2nd command isn't really required, just gives you a dashboard at localhost:8080 where you can check it's being used)

    Cheers,

    Simon

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @OCAPI

    Thanks for the extra information. Yes, the tokens are stored in memory cache by default, so restarting the app causes such a problem. Using Redis will solve this problem as you suggested.

  • User Avatar
    0
    Romka created

    Ok... but we do not use Redis, and we don't plan to enable it just for that bug.

    Another suggestion maybe ?

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @Romka,

    I think the easiest way is to store tokens in database instead of memory cache.

  • User Avatar
    0
    Romka created

    @ismcagdas ok ; any tip on how to do that the clean way ?

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    You can change source code of https://github.com/aspnetzero/aspnet-zero-core/blob/dev/aspnet-core/src/MyCompanyName.AbpZeroTemplate.Core/Authorization/Impersonation/ImpersonationManager.cs and instead of reading tokens from cache you can read them from database.

    In order to do that, you need to define a new entity to store impersonation tokens as well.

  • User Avatar
    0
    Romka created

    Ok I see.

    Thanks for having pointed me in the right direction.

    I can close this ticket I think.

  • User Avatar
    0
    C9Solutions created

    We are experiencing the same issue on 8.9.2, do you have any sample code for converting to the database or any further resolution to the issue?

    Thanks in advance