Web system accessed by various companies appsettings

Asked

Viewed 431 times

2

I am developing an application in ASP.NET Core, in which each company has its own database. The question is: how can I do for the company To access the site by putting user and password and access its information, remembering that there are several companies? There is how to change the appsettings.config for this, another alternative?

I’ve been seeing the question Databases for different customers, not if it would be the right thing to do.

2 answers

1

One of the solutions is to model the bank containing foreign keys for companies.

Ex: You have the user "John" with the foreign key for the company "X", soon when the "John" access the system you will know that you must show the company information "X", this is valid for the other entities of the system.

  • Exactly the problem that the bank will be in the own account that will be replicated the information to the site when asked the information in the browser, and as are several clients each have an external ip and the path of the bank is system standard.

  • I understood, but still do not see need for multiple banks, you can have in the customer a system multi companies that only has a registered company, I imagine that would facilitate the maintenance and also this load in your main system.

0


I’ve been seeing the question Databases for different customers, not if it would be the right thing to do.

It depends. If you want to separate databases by company, it is, but it doesn’t seem to be your case.

I’m guessing you’re using ASP.NET Core Identity. So you need to be familiar with the concept of Claims, that is, portions of identity that your user has.

To add a club to your user, you can use:

await userManager.AddClaimAsync(user, new System.Security.Claims.Claim("empresa", "A"));

Or:

usuario.Claims.Add(new IdentityUserClaim<string> 
{ 
    ClaimType = "empresa", 
    ClaimValue = "A" 
});

contextoIdentity.Entry(usuario).State = EntityState.Modified;
await contextoIdentity.SaveChangesAsync();

Or this answer here. Whatever.

If it is very necessary that you exchange the database, you will also need to change the Connection string at runtime, probably inside a Action Filter, or in the event OnActionExecuting of Controller.

Otherwise, just use the Entityframework.Dynamicfilters package. See here how to use.

  • Opa today the company only works with desktop system, and wants to take it to the web by taking the information from the local database, at first the database will be hosted and fed into the client itself and replicated the information to the site when requested, so I thought the connection string could be dynamic for each login.

  • If that’s the case, you don’t need to. A database just solves everything.

  • I think I explained badly, there will be a connector in the local bank of the company that when the site needs some report, registration or alteration, this connector is triggered, when this connector is without internet something of the type that the company can not access your data, as I described above it looked like it would replicate to another bank but not.

  • Ah, then you better ask another question. You want a contingency mechanism. It has nothing to do with what was asked here until then.

  • Good forgetting this connector that I commented to get better the placement, on the site he should present these bank so the company can choose where it is doubtful, if it would need something to overwrite in appsettings or if there would be another solution or even duplicating the appsettings ?

  • If you want to choose the bank at runtime, it is not using the appsettings.config that you will achieve this. There will have to be a register of companies indicating the database that each uses. When the user logs in, the system searches the company and returns the correct database for each user.

  • That’s exactly, I just don’t know where to go from, how to make the return of the bank say you already have the registration of the company as you would to connect in that database, or bring the string of it?

  • So. Ask another question and paste the link of this question in the other. I put another answer for you.

Show 3 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.