title: ASP.NET Core Middleware and URL Parsing
body: <p>Trying to add special endpoints to an ASP.NET Core MVC through a middleware.</p>
  
  <p>In a <code>app.UseWhen</code>, I need to parse the request URL. In a Controller context, MVC does a great job extracting <code>userId</code> using the following template:</p>
  
  <p><code>GET http://contoso.com/users/{userId}/addresses</code></p>
  
  <p>How could this be cleanly done in a middleware where MVC Controller constructs aren't setup?</p>
  
  <p>Bonus points if the answer helps figuring out if the address conforms to this pattern in the first place.</p>
  
  <p>All I have on hand is a <a href="https://docs.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.http.defaulthttpcontext?view=aspnetcore-2.2" rel="nofollow noreferrer">DefaultHttpContext</a>.</p>