Skip to content

Instantly share code, notes, and snippets.

@prabirshrestha
Created September 10, 2012 03:30
Show Gist options
  • Save prabirshrestha/3688680 to your computer and use it in GitHub Desktop.
Save prabirshrestha/3688680 to your computer and use it in GitHub Desktop.
sample app demon using owin extension methods and fluent api
var app = new List<Func<AppFunc, AppFunc>>();
app
.Use(Favicon.Middleware())
.Use(IeEdgeChromeFrameHeader.Middleware())
.Use(RemovePoweredBy.Middleware())
.Use(CrossDomainRules.Middleware())
.Use(QueryParser.Middleware())
.Use(JsonBodyParser.Middleware())
.Use(UrlEncoded.Middleware())
.Use(MethodOverride.Middleware())
.UriTemplateRoute()
.Configure
["/owin"]
.Cache(c => c.MaxAge = 86400)
.Cache(c => c.Public = true)
["/environment"]
.Application(new EnvironmentApplication())
.End
["/uri"]
.Application(new EnvironmentUriApplication())
.End
["/headers"]
.Application(new EnvironmentRequestHeaders())
.End
.End
["/sample"]
.Get(new ShowFormSample())
.Post(new HandleFormSubmit())
["/scripts"]
.Cache(c => c.MaxAge = 86400)
.Cache(c => c.Public = true)
.Files("scripts")
.End
["/styles"]
.Cache(c => c.MaxAge = 86400)
.Cache(c => c.Public = true)
.Files("scripts")
.End
return app.ToOwinApp()
app
.RegexRouter()
["hello"]
.Use(CrossDomainRules.Middleware())
.Use(RemovePoweredBy.Middleware())
.Get
.Use(next =>
async env =>
{
await env
.GetOwinResponseBody()
.WriteStringAsync("Hello world - GET");
})
.End
.All
.Use(MethodOverride.Middleware())
.Use(next =>
async env =>
{
await env
.GetOwinResponseBody()
.WriteStringAsync("hello world");
})
.End
.End
["*"]
.All
.Use(next =>
async env => {
await env
.SetOwinResponseStatusCode(404)
.GetOwinResponseBody()
.WriteStringAsync("not found");
})
.End
.End
.Unwrap(); // or .End (if using .End you will have to assign it to some variable due to c# limitations)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment