Skip to content
This repository was archived by the owner on Nov 27, 2018. It is now read-only.

Commit a1fe088

Browse files
committed
Removing RouteContext.RequestPath and calculating it from HttpContext as needed.
1 parent a499d4a commit a1fe088

File tree

3 files changed

+6
-8
lines changed

3 files changed

+6
-8
lines changed

samples/RoutingSample.Web/PrefixRoute.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,12 @@ public PrefixRoute(IRouter target, string prefix)
3333

3434
public async Task RouteAsync(RouteContext context)
3535
{
36-
if (context.RequestPath.StartsWith(_prefix, StringComparison.OrdinalIgnoreCase))
36+
var requestPath = context.HttpContext.Request.Path.Value ?? string.Empty;
37+
if (requestPath.StartsWith(_prefix, StringComparison.OrdinalIgnoreCase))
3738
{
38-
if (context.RequestPath.Length > _prefix.Length)
39+
if (requestPath.Length > _prefix.Length)
3940
{
40-
var lastCharacter = context.RequestPath[_prefix.Length];
41+
var lastCharacter = requestPath[_prefix.Length];
4142
if (lastCharacter != '/' && lastCharacter != '#' && lastCharacter != '?')
4243
{
4344
return;

src/Microsoft.AspNet.Routing/RouteContext.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

4-
using Microsoft.AspNet.Http;
54
using System;
5+
using Microsoft.AspNet.Http;
66

77
namespace Microsoft.AspNet.Routing
88
{
@@ -14,16 +14,13 @@ public RouteContext(HttpContext httpContext)
1414
{
1515
HttpContext = httpContext;
1616

17-
RequestPath = httpContext.Request.Path.Value;
1817
RouteData = new RouteData();
1918
}
2019

2120
public HttpContext HttpContext { get; private set; }
2221

2322
public bool IsHandled { get; set; }
2423

25-
public string RequestPath { get; private set; }
26-
2724
public RouteData RouteData
2825
{
2926
get

src/Microsoft.AspNet.Routing/Template/TemplateRoute.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public IDictionary<string, IRouteConstraint> Constraints
7373

7474
public async virtual Task RouteAsync([NotNull] RouteContext context)
7575
{
76-
var requestPath = context.RequestPath;
76+
var requestPath = context.HttpContext.Request.Path.Value;
7777
if (!string.IsNullOrEmpty(requestPath) && requestPath[0] == '/')
7878
{
7979
requestPath = requestPath.Substring(1);

0 commit comments

Comments
 (0)