Skip to content

Commit

Permalink
Servers > HTTP.sys UE pass
Browse files Browse the repository at this point in the history
Updates

Updates

Updates

Update
  • Loading branch information
guardrex committed Feb 27, 2018
1 parent eee39c6 commit 55590a8
Show file tree
Hide file tree
Showing 27 changed files with 378 additions and 148 deletions.
197 changes: 86 additions & 111 deletions aspnetcore/fundamentals/servers/httpsys.md

Large diffs are not rendered by default.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions aspnetcore/fundamentals/servers/httpsys/sample/.bowerrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"directory": "wwwroot/lib"
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@

<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<OutputType>Exe</OutputType>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
</ItemGroup>

</Project>
23 changes: 23 additions & 0 deletions aspnetcore/fundamentals/servers/httpsys/sample/Pages/Error.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
@page
@model ErrorModel
@{
ViewData["Title"] = "Error";
}

<h1 class="text-danger">Error.</h1>
<h2 class="text-danger">An error occurred while processing your request.</h2>

@if (Model.ShowRequestId)
{
<p>
<strong>Request ID:</strong> <code>@Model.RequestId</code>
</p>
}

<h3>Development Mode</h3>
<p>
Swapping to the <strong>Development</strong> environment displays detailed information about the error that occurred.
</p>
<p>
<strong>The Development environment shouldn't be enabled for deployed applications</strong>. It can result in displaying sensitive information from exceptions to end users. For local debugging, enable the Development environment by setting the <strong>ASPNETCORE_ENVIRONMENT</strong> environment variable to <strong>Development</strong> and restarting the app or adding <code>.UseEnvironment("Development")</code> to <code>WebHost</code> in <i>Program.cs</i> and restarting the app.
</p>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System.Diagnostics;
using Microsoft.AspNetCore.Mvc.RazorPages;

namespace HttpSysSample.Pages
{
public class ErrorModel : PageModel
{
public string RequestId { get; private set; }

public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);

public void OnGet()
{
RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier;
}
}
}
28 changes: 28 additions & 0 deletions aspnetcore/fundamentals/servers/httpsys/sample/Pages/Index.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
@page
@model IndexModel
@{
ViewData["Title"] = "HTTP.sys Demo";
}

<h1>@ViewData["Title"]</h1>

<div class="row">
<div class="col-md-6">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">Instructions</h3>
</div>
<div class="panel-body">
<p>Run the app from a command prompt by executing the following command from the project's folder:</p>
<p><code>dotnet run</code></p>
<p>Logging indicates that the <code>HttpSysListener</code> is ready to receive requests:</p>
<p>
<pre><code>info: Microsoft.AspNetCore.Server.HttpSys.HttpSysListener[0]
Start
info: Microsoft.AspNetCore.Server.HttpSys.HttpSysListener[0]
Listening on prefix: http://localhost:5000/</code></pre>
</p>
</div>
</div>
</div>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using Microsoft.AspNetCore.Mvc.RazorPages;

namespace HttpSysSample.Pages
{
public class IndexModel : PageModel
{
public void OnGet()
{
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>@ViewData["Title"]</title>
<environment include="Development">
<link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.css">
<link rel="stylesheet" href="~/css/site.css">
</environment>
<environment exclude="Development">
<link rel="stylesheet" href="https://ajax.aspnetcdn.com/ajax/bootstrap/3.3.7/css/bootstrap.min.css"
asp-fallback-href="~/lib/bootstrap/dist/css/bootstrap.min.css"
asp-fallback-test-class="sr-only" asp-fallback-test-property="position" asp-fallback-test-value="absolute"
crossorigin="anonymous"
integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u">
<link rel="stylesheet" href="~/css/site.min.css" asp-append-version="true">
</environment>
</head>
<body>
<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a asp-page="/Index" class="navbar-brand">HTTP.sys Demo</a>
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li><a asp-page="/Index">Home</a></li>
</ul>
</div>
</div>
</nav>
<div class="container body-content">
@RenderBody()
<hr>
<footer>
<p>&copy;@System.DateTime.Now.Year - HTTP.sys Demo</p>
</footer>
</div>

<environment include="Development">
<script src="~/lib/jquery/dist/jquery.js"></script>
<script src="~/lib/bootstrap/dist/js/bootstrap.js"></script>
<script src="~/js/site.js" asp-append-version="true"></script>
</environment>
<environment exclude="Development">
<script src="https://ajax.aspnetcdn.com/ajax/jquery/jquery-2.2.0.min.js"
asp-fallback-src="~/lib/jquery/dist/jquery.min.js"
asp-fallback-test="window.jQuery"
crossorigin="anonymous"
integrity="sha384-K+ctZQ+LL8q6tP7I94W+qzQsfRV2a+AfHIi9k8z8l9ggpc8X+Ytst4yBo/hH+8Fk">
</script>
<script src="https://ajax.aspnetcdn.com/ajax/bootstrap/3.3.7/bootstrap.min.js"
asp-fallback-src="~/lib/bootstrap/dist/js/bootstrap.min.js"
asp-fallback-test="window.jQuery && window.jQuery.fn && window.jQuery.fn.modal"
crossorigin="anonymous"
integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa">
</script>
<script src="~/js/site.min.js" asp-append-version="true"></script>
</environment>

@RenderSection("Scripts", required: false)
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@using HttpSysSample
@namespace HttpSysSample.Pages
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@{
Layout = "_Layout";
}
17 changes: 4 additions & 13 deletions aspnetcore/fundamentals/servers/httpsys/sample/Program.cs
Original file line number Diff line number Diff line change
@@ -1,38 +1,29 @@
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Server.HttpSys;
using System;

// The default listening address is http://localhost:5000 if none is specified.

namespace HttpSysDemo
namespace HttpSysSample
{
/// <summary>
/// Executing the "dotnet run" command in the application folder will run this app.
/// </summary>
public class Program
{
#region snippet_Main
public static void Main(string[] args)
{
Console.WriteLine("Running demo with HTTP.sys.");

BuildWebHost(args).Run();
}

#region snippet1
public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
#region snippet_Options
.UseHttpSys(options =>
{
// The following options are set to default values.
options.Authentication.Schemes = AuthenticationSchemes.None;
options.Authentication.AllowAnonymous = true;
options.MaxConnections = 100;
options.MaxConnections = null;
options.MaxRequestBodySize = 30000000;
options.UrlPrefixes.Add("http://localhost:5000");
})
#endregion
.Build();
#endregion
}
Expand Down
3 changes: 3 additions & 0 deletions aspnetcore/fundamentals/servers/httpsys/sample/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# ASP.NET Core HTTP.sys Sample

This sample illustrates the use of HTTP.sys. This sample demonstrates the features described in the [HTTP.sys web server implementation](https://docs.microsoft.com/aspnet/core/fundamentals/servers/httpsys) topic.
45 changes: 28 additions & 17 deletions aspnetcore/fundamentals/servers/httpsys/sample/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,38 +1,49 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Hosting.Server.Features;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Extensions;
using Microsoft.AspNetCore.Http.Features;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;

namespace HttpSysDemo
namespace HttpSysSample
{
public class Startup
{
#region snippet_Configure
public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory)
public void ConfigureServices(IServiceCollection services)
{
var serverAddressesFeature = app.ServerFeatures.Get<IServerAddressesFeature>();

app.UseStaticFiles();
services.AddMvc();
}

app.Run(async (context) =>
#region snippet1
public void Configure(IApplicationBuilder app, IHostingEnvironment env,
ILogger<Startup> logger)
{
app.Use(async (context, next) =>
{
context.Features.Get<IHttpMaxRequestBodySizeFeature>()
.MaxRequestBodySize = 10 * 1024;
context.Response.ContentType = "text/html";
await context.Response.WriteAsync("<p>Hosted by HTTP.sys</p>");
var serverAddressesFeature = app.ServerFeatures.Get<IServerAddressesFeature>();
var addresses = string.Join(", ", serverAddressesFeature?.Addresses);
if (serverAddressesFeature != null)
{
await context.Response.WriteAsync($"<p>Listening on the following addresses: {string.Join(", ", serverAddressesFeature.Addresses)}</p>");
}
logger.LogInformation($"Addresses: {addresses}");
await context.Response.WriteAsync($"<p>Request URL: {context.Request.GetDisplayUrl()}</p>");
await next.Invoke();
});

if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseDatabaseErrorPage();
}
else
{
app.UseExceptionHandler("/Error");
}

app.UseStaticFiles();
app.UseMvc();
}
#endregion
#endregion
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"Logging": {
"IncludeScopes": false,
"LogLevel": {
"Default": "Debug",
"System": "Information",
"Microsoft": "Information"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"Logging": {
"IncludeScopes": false,
"LogLevel": {
"Default": "Error",
"System": "Information",
"Microsoft": "Information"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Logging": {
"IncludeScopes": false,
"LogLevel": {
"Default": "Debug"
}
}
}
10 changes: 10 additions & 0 deletions aspnetcore/fundamentals/servers/httpsys/sample/bower.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "asp.net",
"private": true,
"dependencies": {
"bootstrap": "3.3.7",
"jquery": "2.2.0",
"jquery-validation": "1.14.0",
"jquery-validation-unobtrusive": "3.2.6"
}
}
24 changes: 24 additions & 0 deletions aspnetcore/fundamentals/servers/httpsys/sample/bundleconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Configure bundling and minification for the project.
// More info at https://go.microsoft.com/fwlink/?LinkId=808241
[
{
"outputFileName": "wwwroot/css/site.min.css",
// An array of relative input file paths. Globbing patterns supported
"inputFiles": [
"wwwroot/css/site.css"
]
},
{
"outputFileName": "wwwroot/js/site.min.js",
"inputFiles": [
"wwwroot/js/site.js"
],
// Optionally specify minification options
"minify": {
"enabled": true,
"renameLocals": true
},
// Optionally generate .map file
"sourceMap": false
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
body {
padding-top: 50px;
padding-bottom: 20px;
}

h1 {
font-size: 24px;
}

h2 {
font-size: 20px;
}

h3 {
font-size:16px
}

.body-content {
padding-left: 15px;
padding-right: 15px;
}

.panel-body {
font-size: 16px;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
body{padding-top:50px;padding-bottom:20px}h1{font-size:24px}h2{font-size:20px}h3{font-size:16px}.body-content{padding-left:15px;padding-right:15px}.panel-body{font-size:16px}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// Write your Javascript code.
Empty file.
Loading

0 comments on commit 55590a8

Please sign in to comment.