Change Master Page depending on URL

Change MasterPage depending on URL. Is  this possible.

I have 2 departments at work that both use the same site I built but they want to call it by different names. So when I built it back in 2014 I published it twice with two different titles and different name in the master page. So what I want to do (if possible) is put 2 urls to the same site but depending what url they use will affect the masterpage, eg wether the title will say Dept A or Dept B and change the label at the top of the master page to say Dept A or Dept B, or would it be any easier to just make 2 different Master pages and somehow load a different one depending on url.
I have no idea how to go about this so any ideas are greatly appreciated :)
Niall GallagherDeveloperAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Chinmay PatelChief Technology NinjaCommented:
Hi Niall,

You can use Page.PreInit

And based on the conditions you need to change Page.MasterPageFile in PreInit method mentioned above.

David FavorLinux/LXD/WordPress/Hosting SavantCommented:
How you'll approach this will depend on if both site's somehow share the same data or there are 2x different data sets, one specific to each site.

Tip: If something's working, think twice about changing it up.
Niall GallagherDeveloperAuthor Commented:
David, They are the exact same site, hitting the exact same DB, and returning the exact same Data, just both offices want to call it different names
Build an E-Commerce Site with Angular 5

Learn how to build an E-Commerce site with Angular 5, a JavaScript framework used by developers to build web, desktop, and mobile applications.

Chinmay PatelChief Technology NinjaCommented:
Hi Niall,

In that case, just check the URL in Page_Load and change Page.Title and The Labels. I would not recommend going after a separate Master page unless you see a need in future where there can be more than couple of controls to change.

Niall GallagherDeveloperAuthor Commented:
I will try this tomorrow, What would be the best way to check the url they used
Chinmay PatelChief Technology NinjaCommented:
Use Request.Url property and its sub properties per your requirements.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Niall GallagherDeveloperAuthor Commented:
Thank you,
This has definitely helped me to tackle this problem.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.