title: How can I check the URL path to apply a condition (Razor)
body: <p>I am using code like this to detect the browser and apply a condition to display or not display <code>&lt;label&gt;</code>:</p>
  
  <pre><code>@{
  var settings = Model.PartFieldDefinition.Settings.GetModel();
  System.Web.HttpBrowserCapabilitiesBase theBrow = Request.Browser;
  }
  &lt;fieldset&gt;
  @{
     if ((theBrow.Browser == "IE") &amp;&amp; (theBrow.MajorVersion &lt; 10)) 
     {
         @:&lt;label&gt;@Model.DisplayName&lt;/label&gt;
         @://Some Code for inputs
     }
     else 
     {
          @://Some Code for inputs
     }
  }
  &lt;/fieldset&gt;
  </code></pre>
  
  <p>I have been trying to figure out if I can (and if so, how) I could utilize this logic to detect what path in the website the user is in to display or not display <code>&lt;label&gt;</code></p>
  
  <p>For example, on any other path I want the label displayed. However, for the pages under ~/Services (the path), I want to be able to hide the label.</p>
  
  <p>It's a little bit more complicated than that. The code is in an editor template that gets used all over the site. If I use CSS in the editor template to "hide" the label I will affect all the pages. I was hoping with the above logic I can avoid that and only apply my logic on certain pages under a path.</p>
  
  <p>Thanks.</p>
  
  <p><strong>Update</strong>
  I have tried the following:</p>
  
  <pre><code>@{
      string CurrentURL = Request.ApplicationPath;
  }
  &lt;fieldset&gt;
  @{
      if ((CurrentURL == "Services")) // also tried "/Services"
      // rest of code left out for brevity
  }
  </code></pre>
  
  <p>but the labels are hidden on all pages, even outside the path "~/Services". Am stuck on the syntax.</p>
  
  <p><strong>Found answer</strong></p>
  
  <p>I did the following:</p>
  
  <pre><code>@{
      string CurrentURL = Request.Url.AbsoluteUri;
  }
  &lt;fieldset&gt;
  @{
      if (CurrentURL.Contains("Services"))
  }
  </code></pre>
  
  <p>and it worked. I don't know if anyone can comment, but which would be better to use: <code>Request.Url.AbsoluteUri</code> or <code>Request.Url.ToString()</code> (both of which work)?</p>