title: How to retrieve the requesting domain URL in rest?
body: <p>In Global.asax.cs file, I have the code that allows cross domain access.  </p>
  
  <pre><code>    protected void Application_BeginRequest(object sender, EventArgs e)
      {
          HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
          HttpContext.Current.Response.Cache.SetNoStore();
  
          if( // The requesting URL == "http://theproperdomain.com"){
              EnableCrossDmainAjaxCall();
          }
      }  
  
      private void EnableCrossDmainAjaxCall()
      {
          HttpContext.Current.Response.AddHeader("Access-Control-Allow-Origin", "*");
  
          if (HttpContext.Current.Request.HttpMethod == "OPTIONS")
          {
              HttpContext.Current.Response.AddHeader("Access-Control-Allow-Methods", "GET, POST");
              HttpContext.Current.Response.AddHeader("Access-Control-Allow-Headers", "Content-Type, Accept");
              HttpContext.Current.Response.AddHeader("Access-Control-Max-Age", "1728000");
              HttpContext.Current.Response.End();
          }
      }  
  </code></pre>
  
  <p>But before my rest project allows cross domain access, it must check first if the requesting domain is equal to the proper domain. i.e.: "http://theproperdomain.com"  </p>
  
  <p>I have this code:  </p>
  
  <pre><code>string properdomain = HttpContext.Current.Request.Url.AbsoluteUri;  
  </code></pre>
  
  <p>But I'm not sure if it is the best to use.<br>
  Please suggest your better idea.  </p>
  
  <p><strong>Edit</strong>  </p>
  
  <p>My domain server is <code>http://theproperdomain.com</code> where my rest services resides.<br>
  I'll be fetching this domain name from my webconfig and compare to the current accessing client. I need to do this because I want to allow only one domain for "cross domain access".</p>