#14, 52 Add IWebApplicationBuilder.UseIISPlatformHandlerUrl, include path base
This commit is contained in:
parent
11025b894e
commit
0589b883b8
|
|
@ -1,4 +1,5 @@
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections;
|
||||||
using Microsoft.AspNet.Builder;
|
using Microsoft.AspNet.Builder;
|
||||||
using Microsoft.AspNet.Hosting;
|
using Microsoft.AspNet.Hosting;
|
||||||
using Microsoft.AspNet.Http;
|
using Microsoft.AspNet.Http;
|
||||||
|
|
@ -23,10 +24,18 @@ namespace IISSample
|
||||||
context.Response.ContentType = "text/plain";
|
context.Response.ContentType = "text/plain";
|
||||||
await context.Response.WriteAsync("Hello World - " + DateTimeOffset.Now + Environment.NewLine);
|
await context.Response.WriteAsync("Hello World - " + DateTimeOffset.Now + Environment.NewLine);
|
||||||
await context.Response.WriteAsync("User - " + context.User.Identity.Name + Environment.NewLine);
|
await context.Response.WriteAsync("User - " + context.User.Identity.Name + Environment.NewLine);
|
||||||
|
await context.Response.WriteAsync("PathBase: " + context.Request.PathBase.Value + Environment.NewLine);
|
||||||
|
await context.Response.WriteAsync("Path: " + context.Request.Path.Value + Environment.NewLine);
|
||||||
foreach (var header in context.Request.Headers)
|
foreach (var header in context.Request.Headers)
|
||||||
{
|
{
|
||||||
await context.Response.WriteAsync(header.Key + ": " + header.Value + Environment.NewLine);
|
await context.Response.WriteAsync(header.Key + ": " + header.Value + Environment.NewLine);
|
||||||
}
|
}
|
||||||
|
var vars = Environment.GetEnvironmentVariables();
|
||||||
|
foreach (var key in vars.Keys)
|
||||||
|
{
|
||||||
|
var value = vars[key];
|
||||||
|
await context.Response.WriteAsync(key + ": " + value + Environment.NewLine);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -34,6 +43,7 @@ namespace IISSample
|
||||||
{
|
{
|
||||||
var application = new WebApplicationBuilder()
|
var application = new WebApplicationBuilder()
|
||||||
.UseConfiguration(WebApplicationConfiguration.GetDefault(args))
|
.UseConfiguration(WebApplicationConfiguration.GetDefault(args))
|
||||||
|
.UseIISPlatformHandlerUrl()
|
||||||
.UseStartup<Startup>()
|
.UseStartup<Startup>()
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,38 @@
|
||||||
|
// Copyright (c) .NET Foundation. All rights reserved.
|
||||||
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace Microsoft.AspNet.Hosting
|
||||||
|
{
|
||||||
|
public static class IISPlatformHandlerAddressExtensions
|
||||||
|
{
|
||||||
|
// This is defined by IIS's HttpPlatformHandler.
|
||||||
|
private static readonly string ServerPort = "HTTP_PLATFORM_PORT";
|
||||||
|
private static readonly string ServerPath = "HTTP_PLATFORM_APPL_PATH";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Configures the port and base path the server should listen on when running behind HttpPlatformHandler.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="app"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static IWebApplicationBuilder UseIISPlatformHandlerUrl(this IWebApplicationBuilder app)
|
||||||
|
{
|
||||||
|
if (app == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(app));
|
||||||
|
}
|
||||||
|
|
||||||
|
var port = Environment.GetEnvironmentVariable(ServerPort);
|
||||||
|
var path = Environment.GetEnvironmentVariable(ServerPath);
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(port))
|
||||||
|
{
|
||||||
|
var address = "http://localhost:" + port + path;
|
||||||
|
app.UseSetting(WebApplicationDefaults.ServerUrlsKey, address);
|
||||||
|
}
|
||||||
|
|
||||||
|
return app;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -10,13 +10,14 @@
|
||||||
"url": "git://github.com/aspnet/IISIntegration"
|
"url": "git://github.com/aspnet/IISIntegration"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"Microsoft.AspNet.Hosting.Abstractions": "1.0.0-*",
|
||||||
"Microsoft.AspNet.Http": "1.0.0-*",
|
"Microsoft.AspNet.Http": "1.0.0-*",
|
||||||
"Microsoft.AspNet.Http.Extensions": "1.0.0-*",
|
"Microsoft.AspNet.Http.Extensions": "1.0.0-*",
|
||||||
|
"Microsoft.Extensions.Options": "1.0.0-*",
|
||||||
"Microsoft.Extensions.SecurityHelper.Sources": {
|
"Microsoft.Extensions.SecurityHelper.Sources": {
|
||||||
"type": "build",
|
"type": "build",
|
||||||
"version": "1.0.0-*"
|
"version": "1.0.0-*"
|
||||||
},
|
}
|
||||||
"Microsoft.Extensions.Options": "1.0.0-*"
|
|
||||||
},
|
},
|
||||||
"frameworks": {
|
"frameworks": {
|
||||||
"net451": { },
|
"net451": { },
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ namespace TestSites
|
||||||
{
|
{
|
||||||
var application = new WebApplicationBuilder()
|
var application = new WebApplicationBuilder()
|
||||||
.UseConfiguration(WebApplicationConfiguration.GetDefault(args))
|
.UseConfiguration(WebApplicationConfiguration.GetDefault(args))
|
||||||
|
.UseIISPlatformHandlerUrl()
|
||||||
.UseStartup("TestSites")
|
.UseStartup("TestSites")
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue