title: HttpContext GetEndpoint on modified request path .net 5
body: <p>I'm trying to create a middleware to handle country code in the url.
  The code i have works great for removing the country code, so it's routed to the correct endpoint in the mvc pipeline.</p>
  <p>The problem i have is that i need to do some actions depending on if the endpoint has a certain attribute or not.</p>
  <p>I see that <code>HttpContext</code> has a method <code>GetEndpoint</code>, and this is exactly what i need.</p>
  <p>When the countryCode is in the url (mysite.com/<strong>us</strong>/home/Index), the
  <code>GetEndpoint</code> returns null.</p>
  <p>But if i enter the site without the countryCode in the url (mysite.com/home/Index), then the <code>GetEndpoint</code> works.</p>
  <p>How can i use the <code>GetEndpoint()</code> method on the modified request url?</p>
  <p>Is it another property on <code>HttpContext</code> i need to change?</p>
  <pre class="lang-cs prettyprint-override"><code>public async Task InvokeAsync(HttpContext httpContext)
  {
      // mysite.com/us/home/Index
      var currentAddress = httpContext.Request.Path; 
      
      // mysite.com/home/Index
      httpContext.Request.Path = ExtractCountryCodeFromUrl(currentAddress); 
  
      var endpoint = httpContext.GetEndpoint(); // null
  
      var hasMyAttribute = endPoint.Metadata.GetMetadata&lt;MyAttribute&gt;();
      // Do something...
  
      await next(httpContext);
  }
  </code></pre>