Click here to Skip to main content
14,879,366 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
single source communicating with different database but here database name get from subdomain name any body help me.

www://user1.example.com here user1 is subdomain name
Posted
Updated 12-Aug-15 2:55am
v2

1 solution

Get the subdomain like this

C#
string domain = Request.Url.Authority;
string subDomain = domain.Split(new char[] { '.' }, StringSplitOptions.RemoveEmptyEntries)[0];


You can then use that to get the correct connection string. Maybe call your connection string "user1" so you can get it direct from the ConnectionStrings collection. Google "asp.net get connectionsrting" if you don't know how to configure connection strings.
   
Comments
satheeshkumar chinnadurai 12-Aug-15 12:30pm
   
but i need run single source code but different database connection depends upon the first name so. is it possible
F-ES Sitecore 12-Aug-15 14:56pm
   
Yes it's possible, but how you do it depends on how you connect to the database which you haven't stated.
satheeshkumar chinnadurai 13-Aug-15 4:34am
   
ok thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900