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

Commit acd70f7

Browse files
committed
Added hostname parameter to avoid ambiguity
1 parent 312fced commit acd70f7

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

samples/SampleStartups/StartupHelloWorld.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public static void Main()
2222
public static void MainWithPort()
2323
{
2424
var host = new WebHostBuilder()
25-
.Run(8080, async context =>
25+
.Run("localhost", 8080, async context =>
2626
{
2727
await context.Response.WriteAsync("Hello World");
2828
});
@@ -33,13 +33,13 @@ public static void MainWithPort()
3333
public static void MainWithMiddlewareWithPort()
3434
{
3535
var host = new WebHostBuilder()
36-
.RunApplication(8080, app =>
36+
.RunApplication("localhost", 8080, app =>
3737
{
3838
// You can add middleware here
3939
app.Run(async context =>
40-
{
41-
await context.Response.WriteAsync("Hello World");
42-
});
40+
{
41+
await context.Response.WriteAsync("Hello World");
42+
});
4343
});
4444

4545
host.WaitForShutdown();

src/Microsoft.AspNetCore.Hosting/WebHostBuilderExtensions.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,12 @@ public static IWebHost Run(this IWebHostBuilder hostBuilder, RequestDelegate han
110110
/// Runs a web application with the specified handler
111111
/// </summary>
112112
/// <param name="hostBuilder">The <see cref="IWebHostBuilder"/> to run.</param>
113+
/// <param name="hostname">The host name to bind to.</param>
113114
/// <param name="port">The port to bind to.</param>
114115
/// <param name="handler">A delegate that handles the request.</param>
115-
public static IWebHost Run(this IWebHostBuilder hostBuilder, int port, RequestDelegate handler)
116+
public static IWebHost Run(this IWebHostBuilder hostBuilder, string hostname, int port, RequestDelegate handler)
116117
{
117-
var host = hostBuilder.UseUrls($"http://*:{port}/")
118+
var host = hostBuilder.UseUrls($"http://{hostname}:{port}/")
118119
.Configure(app => app.Run(handler))
119120
.Build();
120121
host.Start();
@@ -137,11 +138,12 @@ public static IWebHost RunApplication(this IWebHostBuilder hostBuilder, Action<I
137138
/// Runs a web application with the specified handler
138139
/// </summary>
139140
/// <param name="hostBuilder">The <see cref="IWebHostBuilder"/> to run.</param>
141+
/// <param name="hostname">The host name to bind to.</param>
140142
/// <param name="port">The port to bind to.</param>
141143
/// <param name="configure">The delegate that configures the <see cref="IApplicationBuilder"/>.</param>
142-
public static IWebHost RunApplication(this IWebHostBuilder hostBuilder, int port, Action<IApplicationBuilder> configure)
144+
public static IWebHost RunApplication(this IWebHostBuilder hostBuilder, string hostname, int port, Action<IApplicationBuilder> configure)
143145
{
144-
var host = hostBuilder.UseUrls($"http://*:{port}/")
146+
var host = hostBuilder.UseUrls($"http://{hostname}:{port}/")
145147
.Configure(configure)
146148
.Build();
147149
host.Start();

0 commit comments

Comments
 (0)