Update samples.
This commit is contained in:
parent
60f09fbc93
commit
cb982f19bb
|
|
@ -29,6 +29,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.AspNet.Security.W
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.AspNet.Server.WebListener.FunctionalTests.net45", "test\Microsoft.AspNet.Server.WebListener.FunctionalTests\Microsoft.AspNet.Server.WebListener.FunctionalTests.net45.csproj", "{E7841BDA-EEE0-42D8-8E09-48F021B1934E}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.AspNet.Server.WebListener.FunctionalTests.net45", "test\Microsoft.AspNet.Server.WebListener.FunctionalTests\Microsoft.AspNet.Server.WebListener.FunctionalTests.net45.csproj", "{E7841BDA-EEE0-42D8-8E09-48F021B1934E}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SelfHostServer.k10", "samples\SelfHostServer\SelfHostServer.k10.csproj", "{990662B2-A857-4DD6-85F3-F8517ACAAB13}"
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
|
|
@ -75,6 +77,10 @@ Global
|
||||||
{E7841BDA-EEE0-42D8-8E09-48F021B1934E}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{E7841BDA-EEE0-42D8-8E09-48F021B1934E}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{E7841BDA-EEE0-42D8-8E09-48F021B1934E}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{E7841BDA-EEE0-42D8-8E09-48F021B1934E}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{E7841BDA-EEE0-42D8-8E09-48F021B1934E}.Release|Any CPU.Build.0 = Release|Any CPU
|
{E7841BDA-EEE0-42D8-8E09-48F021B1934E}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{990662B2-A857-4DD6-85F3-F8517ACAAB13}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{990662B2-A857-4DD6-85F3-F8517ACAAB13}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{990662B2-A857-4DD6-85F3-F8517ACAAB13}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{990662B2-A857-4DD6-85F3-F8517ACAAB13}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
|
@ -90,5 +96,6 @@ Global
|
||||||
{8B4EF749-251D-4222-AD18-DE5A1E7D321A} = {99D5E5F3-88F5-4CCF-8D8C-717C8925DF09}
|
{8B4EF749-251D-4222-AD18-DE5A1E7D321A} = {99D5E5F3-88F5-4CCF-8D8C-717C8925DF09}
|
||||||
{3EC418D5-C8FD-47AA-BFED-F524358EC3DD} = {E183C826-1360-4DFF-9994-F33CED5C8525}
|
{3EC418D5-C8FD-47AA-BFED-F524358EC3DD} = {E183C826-1360-4DFF-9994-F33CED5C8525}
|
||||||
{E7841BDA-EEE0-42D8-8E09-48F021B1934E} = {E183C826-1360-4DFF-9994-F33CED5C8525}
|
{E7841BDA-EEE0-42D8-8E09-48F021B1934E} = {E183C826-1360-4DFF-9994-F33CED5C8525}
|
||||||
|
{990662B2-A857-4DD6-85F3-F8517ACAAB13} = {3A1E31E3-2794-4CA3-B8E2-253E96BDE514}
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
EndGlobal
|
EndGlobal
|
||||||
|
|
|
||||||
|
|
@ -1,138 +0,0 @@
|
||||||
// -----------------------------------------------------------------------
|
|
||||||
// <copyright file="Program.cs" company="Microsoft">
|
|
||||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
||||||
// </copyright>
|
|
||||||
// -----------------------------------------------------------------------
|
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Threading;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Microsoft.Owin;
|
|
||||||
using Microsoft.AspNet.Server.WebListener;
|
|
||||||
using Microsoft.Owin.Hosting;
|
|
||||||
using Owin;
|
|
||||||
|
|
||||||
namespace SelfHostServer
|
|
||||||
{
|
|
||||||
// http://owin.org/extensions/owin-WebSocket-Extension-v0.4.0.htm
|
|
||||||
using WebSocketAccept = Action<IDictionary<string, object>, // options
|
|
||||||
Func<IDictionary<string, object>, Task>>; // callback
|
|
||||||
using WebSocketCloseAsync =
|
|
||||||
Func<int /* closeStatus */,
|
|
||||||
string /* closeDescription */,
|
|
||||||
CancellationToken /* cancel */,
|
|
||||||
Task>;
|
|
||||||
using WebSocketReceiveAsync =
|
|
||||||
Func<ArraySegment<byte> /* data */,
|
|
||||||
CancellationToken /* cancel */,
|
|
||||||
Task<Tuple<int /* messageType */,
|
|
||||||
bool /* endOfMessage */,
|
|
||||||
int /* count */>>>;
|
|
||||||
using WebSocketReceiveResult = Tuple<int, // type
|
|
||||||
bool, // end of message?
|
|
||||||
int>; // count
|
|
||||||
using WebSocketSendAsync =
|
|
||||||
Func<ArraySegment<byte> /* data */,
|
|
||||||
int /* messageType */,
|
|
||||||
bool /* endOfMessage */,
|
|
||||||
CancellationToken /* cancel */,
|
|
||||||
Task>;
|
|
||||||
|
|
||||||
public class Program
|
|
||||||
{
|
|
||||||
private static byte[] Data = new byte[1024];
|
|
||||||
|
|
||||||
public static void Main(string[] args)
|
|
||||||
{
|
|
||||||
using (WebApp.Start<Program>(new StartOptions(
|
|
||||||
// "http://localhost:5000/"
|
|
||||||
"https://localhost:9090/"
|
|
||||||
)
|
|
||||||
{
|
|
||||||
ServerFactory = "Microsoft.AspNet.Server.WebListener"
|
|
||||||
}))
|
|
||||||
{
|
|
||||||
Console.WriteLine("Running, press any key to exit");
|
|
||||||
// System.Diagnostics.Process.Start("http://localhost:5000/");
|
|
||||||
Console.ReadKey();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Configuration(IAppBuilder app)
|
|
||||||
{
|
|
||||||
OwinWebListener listener = (OwinWebListener)app.Properties["Microsoft.AspNet.Server.WebListener.OwinWebListener"];
|
|
||||||
listener.AuthenticationManager.AuthenticationTypes =
|
|
||||||
AuthenticationType.Basic |
|
|
||||||
AuthenticationType.Digest |
|
|
||||||
AuthenticationType.Negotiate |
|
|
||||||
AuthenticationType.Ntlm |
|
|
||||||
AuthenticationType.Kerberos;
|
|
||||||
|
|
||||||
app.Use((context, next) =>
|
|
||||||
{
|
|
||||||
Console.WriteLine("Request: " + context.Request.Uri);
|
|
||||||
return next();
|
|
||||||
});
|
|
||||||
app.Use((context, next) =>
|
|
||||||
{
|
|
||||||
if (context.Request.User == null)
|
|
||||||
{
|
|
||||||
context.Response.StatusCode = 401;
|
|
||||||
return Task.FromResult(0);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Console.WriteLine(context.Request.User.Identity.AuthenticationType);
|
|
||||||
}
|
|
||||||
return next();
|
|
||||||
});
|
|
||||||
app.UseWebSockets();
|
|
||||||
app.Use(UpgradeToWebSockets);
|
|
||||||
app.Run(Invoke);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Task Invoke(IOwinContext context)
|
|
||||||
{
|
|
||||||
context.Response.ContentLength = Data.Length;
|
|
||||||
return context.Response.WriteAsync(Data);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Run once per request
|
|
||||||
private Task UpgradeToWebSockets(IOwinContext context, Func<Task> next)
|
|
||||||
{
|
|
||||||
WebSocketAccept accept = context.Get<WebSocketAccept>("websocket.Accept");
|
|
||||||
if (accept == null)
|
|
||||||
{
|
|
||||||
// Not a websocket request
|
|
||||||
return next();
|
|
||||||
}
|
|
||||||
|
|
||||||
accept(null, WebSocketEcho);
|
|
||||||
|
|
||||||
return Task.FromResult<object>(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
private async Task WebSocketEcho(IDictionary<string, object> websocketContext)
|
|
||||||
{
|
|
||||||
var sendAsync = (WebSocketSendAsync)websocketContext["websocket.SendAsync"];
|
|
||||||
var receiveAsync = (WebSocketReceiveAsync)websocketContext["websocket.ReceiveAsync"];
|
|
||||||
var closeAsync = (WebSocketCloseAsync)websocketContext["websocket.CloseAsync"];
|
|
||||||
var callCancelled = (CancellationToken)websocketContext["websocket.CallCancelled"];
|
|
||||||
|
|
||||||
byte[] buffer = new byte[1024];
|
|
||||||
WebSocketReceiveResult received = await receiveAsync(new ArraySegment<byte>(buffer), callCancelled);
|
|
||||||
|
|
||||||
object status;
|
|
||||||
while (!websocketContext.TryGetValue("websocket.ClientCloseStatus", out status) || (int)status == 0)
|
|
||||||
{
|
|
||||||
// Echo anything we receive
|
|
||||||
await sendAsync(new ArraySegment<byte>(buffer, 0, received.Item3), received.Item1, received.Item2, callCancelled);
|
|
||||||
|
|
||||||
received = await receiveAsync(new ArraySegment<byte>(buffer), callCancelled);
|
|
||||||
}
|
|
||||||
|
|
||||||
await closeAsync((int)websocketContext["websocket.ClientCloseStatus"], (string)websocketContext["websocket.ClientCloseDescription"], callCancelled);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -0,0 +1,20 @@
|
||||||
|
using Microsoft.AspNet.Abstractions;
|
||||||
|
using Microsoft.AspNet.Server.WebListener;
|
||||||
|
|
||||||
|
namespace SelfHostServer
|
||||||
|
{
|
||||||
|
public class Startup
|
||||||
|
{
|
||||||
|
public void Configuration(IBuilder app)
|
||||||
|
{
|
||||||
|
var info = (ServerInformation)app.Server;
|
||||||
|
info.Listener.AuthenticationManager.AuthenticationTypes = AuthenticationType.None;
|
||||||
|
|
||||||
|
app.Run(async context =>
|
||||||
|
{
|
||||||
|
context.Response.ContentType = "text/plain";
|
||||||
|
await context.Response.WriteAsync("Hello world");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,19 +1,33 @@
|
||||||
{
|
{
|
||||||
"version" : "0.1-alpha-*",
|
"version" : "0.1-alpha-*",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"Microsoft.AspNet.Server.WebListener" : "",
|
"Microsoft.AspNet.Abstractions": "0.1-alpha-*",
|
||||||
"Microsoft.AspNet.WebSockets" : ""
|
"Microsoft.AspNet.Hosting": "0.1-alpha-*",
|
||||||
|
"Microsoft.AspNet.Server.WebListener": ""
|
||||||
},
|
},
|
||||||
|
"commands": { "web": "Microsoft.AspNet.Hosting server.name=Microsoft.AspNet.Server.WebListener server.urls=http://localhost:5001" },
|
||||||
"configurations": {
|
"configurations": {
|
||||||
"net45": {
|
"net45": {
|
||||||
|
},
|
||||||
|
"k10": {
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"Owin": "1.0",
|
"System.Console": "4.0.0.0",
|
||||||
"Microsoft.Owin": "2.1.0",
|
"System.Collections": "4.0.0.0",
|
||||||
"Microsoft.Owin.Diagnostics": "2.1.0",
|
"System.Diagnostics.Debug": "4.0.10.0",
|
||||||
"Microsoft.Owin.Hosting": "2.1.0",
|
"System.Diagnostics.Tools": "4.0.0.0",
|
||||||
"Microsoft.Owin.Host.HttpListener": "2.1.0",
|
"System.Globalization": "4.0.10.0",
|
||||||
"Microsoft.AspNet.AppBuilderSupport": "0.1-alpha-*"
|
"System.IO": "4.0.0.0",
|
||||||
}
|
"System.IO.FileSystem": "4.0.0.0",
|
||||||
|
"System.IO.FileSystem.Primitives": "4.0.0.0",
|
||||||
|
"System.Linq": "4.0.0.0",
|
||||||
|
"System.Reflection": "4.0.10.0",
|
||||||
|
"System.Resources.ResourceManager": "4.0.0.0",
|
||||||
|
"System.Runtime": "4.0.20.0",
|
||||||
|
"System.Runtime.Extensions": "4.0.10.0",
|
||||||
|
"System.Runtime.InteropServices": "4.0.10.0",
|
||||||
|
"System.Text.Encoding": "4.0.10.0",
|
||||||
|
"System.Threading.Tasks": "4.0.10.0"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue