How to refer to main domain without hard-coding its name?

后端 未结 4 2093
半阙折子戏
半阙折子戏 2021-02-19 22:01

I have a domain name: TestSite.com. I create several subdomains for this site and refer to them as first.TestSite.com, second.TestSite.com, etc.

How do I refer to TestSi

4条回答
  •  后悔当初
    2021-02-19 22:28

    If you want to keep your relative links, you can use the base element.

    [The base element's href] attribute specifies an absolute URI that acts as the base URI for resolving relative URIs.

    So, add a base element, specify the href you'd like, and all the relative URIs on the page now use the URI you've specified as the base URI.

    
        
    
    

    That's all you need. However, if you'd like to make things a little cleaner, you can pull that URI from the web.config using System.Configuration.ConfigurationManager.AppSettings. Here's an aspx snippet:

    
        " />
    
    

    And the web.config:

    
      
         
      
    
    

    This method allows you to affect many elements from one and its value can be driven from the web.config.

提交回复
热议问题