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

Add IWebApplicationBuilder.UseIISPlatformHandlerUrl, include path base #61

Merged
merged 1 commit into from
Jan 12, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions samples/IISSample/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections;
using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Hosting;
using Microsoft.AspNet.Http;
Expand All @@ -23,17 +24,26 @@ public void Configure(IApplicationBuilder app, ILoggerFactory loggerfactory)
context.Response.ContentType = "text/plain";
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("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)
{
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);
}
});
}

public static void Main(string[] args)
{
var application = new WebApplicationBuilder()
.UseConfiguration(WebApplicationConfiguration.GetDefault(args))
.UseIISPlatformHandlerUrl()
.UseStartup<Startup>()
.Build();

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
5 changes: 3 additions & 2 deletions src/Microsoft.AspNet.IISPlatformHandler/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@
"url": "git://github.com/aspnet/IISIntegration"
},
"dependencies": {
"Microsoft.AspNet.Hosting.Abstractions": "1.0.0-*",
"Microsoft.AspNet.Http": "1.0.0-*",
"Microsoft.AspNet.Http.Extensions": "1.0.0-*",
"Microsoft.Extensions.Options": "1.0.0-*",
"Microsoft.Extensions.SecurityHelper.Sources": {
"type": "build",
"version": "1.0.0-*"
},
"Microsoft.Extensions.Options": "1.0.0-*"
}
},
"frameworks": {
"net451": { },
Expand Down
1 change: 1 addition & 0 deletions test/TestSites/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public static void Main(string[] args)
{
var application = new WebApplicationBuilder()
.UseConfiguration(WebApplicationConfiguration.GetDefault(args))
.UseIISPlatformHandlerUrl()
.UseStartup("TestSites")
.Build();

Expand Down