anujs
anujs

Reputation: 47

Use different connection string based on the application url in .net

I have a asp.net web project named FinanceTracker (which is under use for an year). And the data is stored in Finance_Tracker_db. (this is a intranet web site to track the financial data for an organization, accessed from http://OrgTracker) Now I have a requirement to have the same application for IT department. everything is same on the data for both should be segregated. So I created an empty copy of database name IT_Tracker_db.(on same database server) And used the old code with modified connection string in web.config (accessed from http://OrgTracker/IT/ deployed on same IIS server)

But as to have less maintenance to apply the same code to both deployed version, I am planning to use the same code with different connection strings.

Now I wish to have something like.

http://OrgTracker/ - This should show two links

  1. http://OrgTracker/fincance/
  2. http://OrgTracker/IT/

And based on user selected URL the proper connection string should be used from web.config

Like all pages will remain same like.

http://OrgTracker/fincance/Status.aspx, http://OrgTracker/fincance/Inbox.aspx, etc.

http://OrgTracker/IT/Status.aspx, http://OrgTracker/IT/Inbox.aspx, etc.

Upvotes: 0

Views: 1862

Answers (2)

paparazzo
paparazzo

Reputation: 45096

Can have more than one config

ASP.NET Configuration File Hierarchy and Inheritance

Upvotes: 1

Dmitry Osinovskiy
Dmitry Osinovskiy

Reputation: 10118

I suggest not doing this. First, it is complicated and out of build-in ASP.NET functionality. Second, in some time in future your users can demand different things: one department would want newer version immediately, while the other one would want to have stable old version until they can test everything.

P.S. But if I were you, I'd start thinking about adding additional column called "Department" in all relevant tables so I could unite databases in future. This goes against my second point :), but it would make everything more manageable and architecturally sound, especially if more departments would want to use your application.

Upvotes: 0

Related Questions