SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need to determine the 'main' server name based on the My Site server name in a control. This control needs to work in multiple environments with a different set of servers in each.

Example: My Site URL: http://My-Dev 'Main' site URL: http://Dev

What I (think I) need to do is to get the My Site server name (My-Dev in the example), test it, and come up with the corresponding main server name.

I'm sure I could write a RegExp against the URL but it seems to me I've seen the Server property of some SP object somewhere before.

share|improve this question
I think like Dave asks Main Server doesn't always apply in many SharePoint instances, such as a Farm environment where there may be a Central Admin and multiple Web Front Ends. Main Server in that context doesn't make much sense. – MichaelF Jul 15 '11 at 18:10

There is no 'main' web application for a MySite because a single MySite can be used by multiple web applications. If you know that you will always have one and only one 'main' web app associated with your MySite then it would probably be better to define an AppSetting in the web.config of the MySite and reference it via ConfigurationManager.AppSettings. There are certainly other options but that is the simplest.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.