Skip to content

Instantly share code, notes, and snippets.

@aodag
Created March 2, 2014 06:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aodag/9302663 to your computer and use it in GitHub Desktop.
Save aodag/9302663 to your computer and use it in GitHub Desktop.
OwinContextなしで、KatanaのStartupを利用
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Threading.Tasks;
using System.IO;
using System.Text;
namespace OwinSample
{
public class HelloApp
{
string message;
public HelloApp(object next, string message)
{
this.message = message;
}
public Task Invoke(IDictionary<string, object> env)
{
var headers = env["owin.ResponseHeaders"] as IDictionary<string, string[]>;
headers["Content-type"] = new string[]{"text/plain;charset=utf-8"};
var contents = Encoding.UTF8.GetBytes(message);
var body = env["owin.ResponseBody"] as Stream;
return body.WriteAsync(contents, 0, contents.Length);
}
}
}
using System;
using System.Threading.Tasks;
using Microsoft.Owin;
using Owin;
[assembly: OwinStartup(typeof(OwinSample.Startup))]
namespace OwinSample
{
public class Startup
{
public void Configuration(IAppBuilder app)
{
app.Use<HelloApp>("Hello, world!");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment