• Visitors can check out the Forum FAQ by clicking this link. You have to register before you can post: click the REGISTER link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. View our Forum Privacy Policy.
  • Want to receive the latest contracting news and advice straight to your inbox? Sign up to the ContractorUK newsletter here. Every sign up will also be entered into a draw to WIN £100 Amazon vouchers!

You are not logged in or you do not have permission to access this page. This could be due to one of several reasons:

  • You are not logged in. If you are already registered, fill in the form below to log in, or follow the "Sign Up" link to register a new account.
  • You may not have sufficient privileges to access this page. Are you trying to edit someone else's post, access administrative features or some other privileged system?
  • If you are trying to post, the administrator may have disabled your account, or it may be awaiting activation.

Previously on "Multi-tenant ASP.NET core application, handling multiple tabs?"

Collapse

  • woohoo
    replied
    It's an option to push the tenant id in the URL or have a hidden field. It just seemed like it was an inelegant solution that meant I would have to touch more of the existing codebase. Then have to test more. Didn't really want to spend more than a few hours on this problem.

    I don't think I mentioned it but the admin system was originally just to look after one tenant - two tenants meant two different admin systems. So this new admin system was really bringing that together, along with a few other features. So I really was working with an existing codebase and database.

    Guids would have made the whole thing safer but there you go.

    Leave a comment:


  • BlueSharp
    replied
    Originally posted by woohoo View Post
    For what it's worth in case anyone is still interested. I ended up implementing SignalR.

    Each connection (tab/window) is added to a group based on username, when the tenant is selected from the drop down, javascript calls a method via ajax to set the cookie tenant value (could have done it via javascript). Then a server side method on the tenant hub is called from the client. This method broadcasts to the group and triggers a method on the browsers belonging to that group and redirects to the home page.

    A bit overkill if im honest, but found it interesting.
    Sounds like a workable solution. Why the reluctance to use the tenant id in the url? If you're calling back end api's you could of taken the tenant id from a hidden form field and added it to to the api request url or as a header value on the api request.

    Leave a comment:


  • woohoo
    replied
    For what it's worth in case anyone is still interested. I ended up implementing SignalR.

    Each connection (tab/window) is added to a group based on username, when the tenant is selected from the drop down, javascript calls a method via ajax to set the cookie tenant value (could have done it via javascript). Then a server side method on the tenant hub is called from the client. This method broadcasts to the group and triggers a method on the browsers belonging to that group and redirects to the home page.

    A bit overkill if im honest, but found it interesting.

    Leave a comment:


  • woohoo
    replied
    Not sure, which is why im asking the question.

    Leave a comment:


  • eek
    replied
    Originally posted by woohoo View Post
    Im not really a fan of the way MS handle switching between tenants. It's a mess tbh.

    If you look at Xero for example they do it almost exactly how I want.

    My feeling is I will have to dive into ASP.NET core lifecycle and check earlier in the page lifecycle and redirect if the value in the cookie changes.
    How would you know the value of the cookie has changed?

    Leave a comment:


  • woohoo
    replied
    Im not really a fan of the way MS handle switching between tenants. It's a mess tbh.

    If you look at Xero for example they do it almost exactly how I want.

    My feeling is I will have to dive into ASP.NET core lifecycle and check earlier in the page lifecycle and redirect if the value in the cookie changes.

    Leave a comment:


  • eek
    replied
    There is a reason why MS will throw you got of the first tenant if you enter a second one.

    I don't think there is a solution beyond adding enough state information / logic within the Web page to know what tenant the page belongs to and when the tenant no longer matches throw an error message.

    MS's solution when asked about this is to train users to use the multiple profiles that are now available on chrome and Edge, my advice would be the same.

    Leave a comment:


  • Multi-tenant ASP.NET core application, handling multiple tabs?

    I have an admin system, the customer can select a tenant from a drop down box and website redirects to the tenant home page. The customer can continue to maintain the tenant data.

    The problem I could have is if a customer opens tenant A in tab 1, then in tab 2 opens tenant B. If they go back to tab 1 and save a customer record for example it will try to save the record against tenant b.

    I use a scoped tenant class with a connection string in it, middleware on each request checks a cookie for the tenant id and places the tenant connection string in the scoped class. The scoped class is used by the repositories to retrieve the correct tenant data.

    So in the example above tab 2 will change the cookie tenant id, the middleware will change the scoped connection string and when tab 1 saves its using tenant B connection string.

    I have a nasty JavaScript hack that keeps track of open admin tabs and closes and warns the user. It's a nasty hack, causing more issues that it's worth.

    Anyone any ideas, oh and I really want to avoid having the tenant id in the query string. I'm thinking of something earlier in the life cycle of the page to catch the change and in this case redirect the request to the home page for the tenant.

    I know it's a long shot, but any ideas? Stackoverflow has failed me. Thanks in advance.

Working...
X