title: treat AbsoluteUri C#
body: <p>I'm trying to figure out what is the best way to treat an <code>URL</code> from a <code>MVC</code> project.</p>
  
  <p>As you will see I'm reading a XML file to distinguish witch client goes where into <code>IIS</code>.</p>
  
  <p>My problem is, sometimes i get empty URl, sometimes clients gets redirect to a wrong path. As I'm using <code>node.Value.Contains(ClientUrl)</code> and  <code>.FirstOrDefault()</code>. so  whenever that happens I need to adapt the XML to it like adding <code>/login#</code> etc..
  As all <code>URL's</code> are Kind similar I would like to treat the URL/path to each client an use  <code>node.Value.Equals(ClientUrl)</code> instead.</p>
  
  <p>Thanks all.</p>
  
  <p>Controller</p>
  
  <pre><code>    public ActionResult Index(string returnUrl)
      {
          try
          {
              Response.ClearContent();
              Response.ClearHeaders();
              Response.Cache.SetExpires(DateTime.UtcNow.AddMinutes(-1));
              Response.Cache.SetCacheability(HttpCacheability.NoCache);
              Response.Cache.SetNoStore();               
  
              var useragent = Request.UserAgent;
              string UrlDoCliente = Request.Url.AbsoluteUri;
              SysConfig _SysConfig = new SysConfig(ClientUrl);
              var isAndroid = false;
              int Id = SyscoopWebConfig.Empresa;
              if (useragent != null)
              {
                  if (useragent.ToLower().Contains("Android".ToLower()))
                  {
                      isAndroid = true;
                  }
                  else
                  {
                      isAndroid = Request.Browser.IsMobileDevice;
                  }
              }
  
              if (isAndroid)
              {
                  string url = SysWebConfig.urlAppMobile;
                  if (url != "")
                  {
                      return Redirect(url);
                  }
              }
  
              if (!Request.IsAuthenticated)
              {
                  Session["sesParam"] = null;
                  return Redirect(SysWebConfig.urlAppDesktop + "/login#");
              }
          }
          catch (Exception e)
          {
              ViewBag.message = e.Message.ToString() + ". Url wsdl: " + SysWebConfig.Wsdl;
          }
  
          return View();
      }
  </code></pre>
  
  <p>Reading xml</p>
  
  <pre><code>    private static void readXMLConfig(string ClientUrl)
      {
          try
          {
  
              XmlDocument docX = new XmlDocument();
  
              string sysWebPath = AppDomain.CurrentDomain.BaseDirectory;
  
              docX.Load(WebPath + "/SysWebConfig.xml");
  
              XElement xml = docX.ToXElement();
              var config   = (from nodes in xml.Descendants("client")
                                from node in nodes.Attributes("url")
                                where node.Value.Contains(ClientUrl)
                                 select nodes).FirstOrDefault();
  
              if (config != null)
              {
                  _client = int.Parse(config.Element("clientId").Value);
                  _wsdl = config.Element("wsdl").Value;
                  _urlAppMobile = config.Element("urlAppMobile").Value;
                  _urlAppDesktop = config.Element("urlAppDesktop").Value;
              }
  
          }
          catch (Exception)
          {
              throw new Exception('error reading xml file');
          }
      }
  </code></pre>
  
  <p>XML sample </p>
  
  <pre><code>    &lt;?xml version="1.0" encoding="utf-8"?&gt;
      &lt;ClientConfig&gt;
        &lt;SysWeb&gt;
         &lt;client url="http://192.168.2.31/sysweb/client1"&gt;
              &lt;wsdl&gt;http://192.168.2.25/wssysweb/sysweb.dll/soap/ISysWeb&lt;/wsdl&gt;
              &lt;clientId&gt;001&lt;/clientId&gt;
              &lt;urlAppMobile&gt;http://192.168.2.31/syswebmobile/AppClient1&lt;/urlAppMobile&gt;
              &lt;urlAppDesktop&gt;http://192.168.2.31/sysweb/AppClient1&lt;/urlAppDesktop&gt;
          &lt;/client&gt;
         &lt;client url="http://192.168.2.31/sysweb/client1/login#"&gt;
              &lt;wsdl&gt;http://192.168.2.25/wssysweb/sysweb.dll/soap/ISysWeb&lt;/wsdl&gt;
              &lt;clientId&gt;001&lt;/clientId&gt;
              &lt;urlAppMobile&gt;http://192.168.2.31/syswebmobile/AppClient1&lt;/urlAppMobile&gt;
              &lt;urlAppDesktop&gt;http://192.168.2.31/sysweb/AppClient1&lt;/urlAppDesktop&gt;
          &lt;/client&gt;       
          &lt;client url="http://192.168.2.31/sysweb/client2"&gt;
              &lt;wsdl&gt;http://192.168.2.25/wssyweb/syspweb.dll/soap/ISysWeb&lt;/wsdl&gt;
              &lt;clientId&gt;002&lt;/clientId&gt;
              &lt;urlAppMobile&gt;http://192.168.2.31/syswebmobile/AppClient2&lt;/urlAppMobile&gt;
              &lt;urlAppDesktop&gt;http://192.168.2.31/sysweb/AppClient2&lt;/urlAppDesktop&gt;
          &lt;/client&gt;       
          &lt;client url="http://192.168.2.31/sysweb/client3"&gt;
              &lt;wsdl&gt;http://192.168.2.25/wssyweb/syspweb.dll/soap/ISysWeb&lt;/wsdl&gt;
              &lt;clientId&gt;003&lt;/clientId&gt;
              &lt;urlAppMobile&gt;http://192.168.2.31/syswebmobile/AppClient3&lt;/urlAppMobile&gt;
              &lt;urlAppDesktop&gt;http://192.168.2.31/sysweb/AppClient3&lt;/urlAppDesktop&gt;
          &lt;/client&gt;       
        &lt;/SysWeb&gt;
      &lt;/ClientConfig&gt;
  </code></pre>