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

Commit fbf472c

Browse files
committed
Improve IUrlHelper and related doc comments
- #4245, #4507
1 parent 42cea41 commit fbf472c

File tree

5 files changed

+95
-65
lines changed

5 files changed

+95
-65
lines changed

src/Microsoft.AspNetCore.Mvc.Abstractions/IUrlHelper.cs

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@ public interface IUrlHelper
1616
ActionContext ActionContext { get; }
1717

1818
/// <summary>
19-
/// Generates a fully qualified or absolute URL specified by <see cref="UrlActionContext"/> for an action
20-
/// method, which contains action name, controller name, route values, protocol to use, host name, and fragment.
19+
/// Generates a URL with an absolute path for an action method, which contains the action
20+
/// name, controller name, route values, protocol to use, host name, and fragment specified by
21+
/// <see cref="UrlActionContext"/>. Generates an absolute URL if <see cref="UrlActionContext.Protocol"/> and
22+
/// <see cref="UrlActionContext.Host"/> are non-<c>null</c>.
2123
/// </summary>
2224
/// <param name="actionContext">The context object for the generated URLs for an action method.</param>
23-
/// <returns>The fully qualified or absolute URL to an action method.</returns>
25+
/// <returns>The URL with an absolute path for an action method.</returns>
2426
string Action(UrlActionContext actionContext);
2527

2628
/// <summary>
@@ -35,43 +37,47 @@ public interface IUrlHelper
3537
string Content(string contentPath);
3638

3739
/// <summary>
38-
/// Returns a value that indicates whether the URL is local. A URL with an absolute path is considered local
39-
/// if it does not have a host/authority part. URLs using virtual paths ('~/') are also local.
40+
/// Returns a value that indicates whether the URL is local. A URL is considered local if it does not have a
41+
/// host / authority part and it has an absolute path. URLs using virtual paths ('~/') are also local.
4042
/// </summary>
4143
/// <param name="url">The URL.</param>
4244
/// <returns><c>true</c> if the URL is local; otherwise, <c>false</c>.</returns>
4345
/// <example>
4446
/// <para>
4547
/// For example, the following URLs are considered local:
48+
/// <code>
4649
/// /Views/Default/Index.html
4750
/// ~/Index.html
51+
/// </code>
4852
/// </para>
4953
/// <para>
5054
/// The following URLs are non-local:
55+
/// <code>
5156
/// ../Index.html
5257
/// http://www.contoso.com/
5358
/// http://localhost/Index.html
59+
/// </code>
5460
/// </para>
5561
/// </example>
5662
bool IsLocalUrl(string url);
5763

5864
/// <summary>
59-
/// Generates a fully qualified or absolute URL specified by <see cref="UrlRouteContext"/>, which
60-
/// contains the route name, the route values, protocol to use, host name and fragment.
65+
/// Generates a URL with an absolute path, which contains the route name, route values, protocol to use, host
66+
/// name, and fragment specified by <see cref="UrlRouteContext"/>. Generates an absolute URL if
67+
/// <see cref="UrlActionContext.Protocol"/> and <see cref="UrlActionContext.Host"/> are non-<c>null</c>.
6168
/// </summary>
6269
/// <param name="routeContext">The context object for the generated URLs for a route.</param>
63-
/// <returns>The fully qualified or absolute URL.</returns>
70+
/// <returns>The URL with an absolute path.</returns>
6471
string RouteUrl(UrlRouteContext routeContext);
6572

6673
/// <summary>
67-
/// Generates an absolute URL using the specified route name and values.
74+
/// Generates an absolute URL for the specified <paramref name="routeName"/> and route
75+
/// <paramref name="values"/>, which contains the protocol (such as "http" or "https") and host name from the
76+
/// current request.
6877
/// </summary>
69-
/// <param name="routeName">The name of the route that is used to generate the URL.</param>
70-
/// <param name="values">An object that contains the route values.</param>
71-
/// <returns>The generated absolute URL.</returns>
72-
/// <remarks>
73-
/// The protocol and host is obtained from the current request.
74-
/// </remarks>
78+
/// <param name="routeName">The name of the route that is used to generate URL.</param>
79+
/// <param name="values">An object that contains route values.</param>
80+
/// <returns>The absolute URL.</returns>
7581
string Link(string routeName, object values);
7682
}
7783
}

src/Microsoft.AspNetCore.Mvc.Abstractions/Routing/UrlActionContext.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public string Controller
2727
}
2828

2929
/// <summary>
30-
/// The object that contains the route parameters that <see cref="IUrlHelper.Action(UrlActionContext)"/>
30+
/// The object that contains the route values that <see cref="IUrlHelper.Action(UrlActionContext)"/>
3131
/// uses to generate URLs.
3232
/// </summary>
3333
public object Values
@@ -37,7 +37,7 @@ public object Values
3737
}
3838

3939
/// <summary>
40-
/// The protocol for the URLs that <see cref="IUrlHelper.Action(UrlActionContext)"/> generates
40+
/// The protocol for the URLs that <see cref="IUrlHelper.Action(UrlActionContext)"/> generates,
4141
/// such as "http" or "https"
4242
/// </summary>
4343
public string Protocol

src/Microsoft.AspNetCore.Mvc.Abstractions/Routing/UrlRouteContext.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ public string RouteName
1818
}
1919

2020
/// <summary>
21-
/// The object that contains the route values for the generated URLs.
21+
/// The object that contains the route values that <see cref="IUrlHelper.RouteUrl(UrlRouteContext)"/>
22+
/// uses to generate URLs.
2223
/// </summary>
2324
public object Values
2425
{
@@ -27,7 +28,7 @@ public object Values
2728
}
2829

2930
/// <summary>
30-
/// The protocol for the URLs that <see cref="IUrlHelper.RouteUrl(UrlRouteContext)"/> generates
31+
/// The protocol for the URLs that <see cref="IUrlHelper.RouteUrl(UrlRouteContext)"/> generates,
3132
/// such as "http" or "https"
3233
/// </summary>
3334
public string Protocol

src/Microsoft.AspNetCore.Mvc.Core/Routing/UrlHelper.cs

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ public class UrlHelper : IUrlHelper
2323
private readonly RouteValueDictionary _routeValueDictionary;
2424

2525
/// <summary>
26-
/// Initializes a new instance of the <see cref="UrlHelper"/> class using the specified action context and
27-
/// action selector.
26+
/// Initializes a new instance of the <see cref="UrlHelper"/> class using the specified
27+
/// <paramref name="actionContext"/>.
2828
/// </summary>
2929
/// <param name="actionContext">The <see cref="Mvc.ActionContext"/> for the current request.</param>
3030
public UrlHelper(ActionContext actionContext)
@@ -41,10 +41,19 @@ public UrlHelper(ActionContext actionContext)
4141
/// <inheritdoc />
4242
public ActionContext ActionContext { get; }
4343

44+
/// <summary>
45+
/// Gets the <see cref="RouteValueDictionary"/>.
46+
/// </summary>
4447
protected RouteValueDictionary AmbientValues => ActionContext.RouteData.Values;
4548

49+
/// <summary>
50+
/// Gets the <see cref="Http.HttpContext"/>
51+
/// </summary>
4652
protected HttpContext HttpContext => ActionContext.HttpContext;
4753

54+
/// <summary>
55+
/// Gets the <see cref="IRouter"/>.
56+
/// </summary>
4857
protected IRouter Router => ActionContext.RouteData.Routers[0];
4958

5059
/// <inheritdoc />
@@ -116,11 +125,12 @@ public virtual string RouteUrl(UrlRouteContext routeContext)
116125
}
117126

118127
/// <summary>
119-
/// Gets the <see cref="VirtualPathData"/> for the specified route values by using the specified route name.
128+
/// Gets the <see cref="VirtualPathData"/> for the specified <paramref name="routeName"/> and route
129+
/// <paramref name="values"/>.
120130
/// </summary>
121131
/// <param name="routeName">The name of the route that is used to generate the <see cref="VirtualPathData"/>.
122132
/// </param>
123-
/// <param name="values">A dictionary that contains the parameters for a route.</param>
133+
/// <param name="values">The <see cref="RouteValueDictionary"/>.</param>
124134
/// <returns>The <see cref="VirtualPathData"/>.</returns>
125135
protected virtual VirtualPathData GetVirtualPathData(string routeName, RouteValueDictionary values)
126136
{
@@ -253,10 +263,10 @@ private StringBuilder GetStringBuilder()
253263
/// <summary>
254264
/// Generates the URL using the specified components.
255265
/// </summary>
256-
/// <param name="protocol">The protocol.</param>
257-
/// <param name="host">The host.</param>
266+
/// <param name="protocol">The protocol for the URL, such as "http" or "https".</param>
267+
/// <param name="host">The host name for the URL.</param>
258268
/// <param name="pathData">The <see cref="VirtualPathData"/>.</param>
259-
/// <param name="fragment">The URL fragment.</param>
269+
/// <param name="fragment">The fragment for the URL.</param>
260270
/// <returns>The generated URL.</returns>
261271
protected virtual string GenerateUrl(string protocol, string host, VirtualPathData pathData, string fragment)
262272
{
@@ -268,7 +278,7 @@ protected virtual string GenerateUrl(string protocol, string host, VirtualPathDa
268278
// VirtualPathData.VirtualPath returns string.Empty instead of null.
269279
Debug.Assert(pathData.VirtualPath != null);
270280

271-
// Perf: In most of the common cases, GenerateUrl is called with a null protocol, host and fragment.
281+
// Perf: In most of the common cases, GenerateUrl is called with a null protocol, host and fragment.
272282
// In such cases, we might not need to build any URL as the url generated is mostly same as the virtual path available in pathData.
273283
// For such common cases, this FastGenerateUrl method saves a string allocation per GenerateUrl call.
274284
string url;

0 commit comments

Comments
 (0)