public void Configuration(IAppBuilder builder) { // routes can be added for each path prefix that should be // mapped to owin RouteTable.Routes.AddOwinRoute("hello"); RouteTable.Routes.AddOwinRoute("world"); // the routes above will be map onto whatever is added to // the IAppBuilder builder that was passed into this method builder.UseDirect((req, res) => { res.ContentType = "text/plain"; res.Write("Hello from " + req.PathBase + req.Path); return res.EndAsync(); }); // a route may also be added for a given builder method. // this can also be done from global.asax RouteTable.Routes.AddOwinRoute("wilson-async", builder, x => x.UseShowExceptions().UseContentType("text/plain").Run(WilsonAsync.App())); // a route may also be added for a given builder method. // this can also be done from global.asax RouteTable.Routes.AddOwinRoute("wilson", builder, x => x.UseShowExceptions().UseContentType("text/plain").Run(Wilson.App())); // a route may also be added for a given app delegate // this can also be done from global.asax RouteTable.Routes.AddOwinRoute("raw", Raw); }
public void Configuration(IAppBuilder builder) { builder.UseDirect((req, resp) => { resp.Status = "200 OK"; resp.ContentType = "text/html"; resp.SetCookie("my-cookie", "my-value"); resp.SetCookie("my-30-day-cookie", new Response.Cookie("hello-this-month") { Expires = DateTime.UtcNow.AddDays(30) }); resp.SetCookie("last-path-cookie", new Response.Cookie("hello-path " + req.Path) { Path = req.PathBase + req.Path }); resp.Write("<html>"); resp.Write("<head><title>Hello world</title></head>"); resp.Write("<body>"); resp.Write("<p>Hello world!</p>"); resp.Write("<ul>"); resp.Write("<h3>Environment</h3>"); foreach (var kv in req.Environment) { resp.Write("<li>«"); resp.Write(kv.Key); resp.Write("»<br/><code>"); resp.Write(kv.Value.ToString()); resp.Write("</code></li>"); } resp.Write("<h3>Headers</h3>"); foreach (var kv2 in req.Headers) { resp.Write("<li>«"); resp.Write(kv2.Key); resp.Write("» = "); resp.Write(string.Join(", ", kv2.Value.ToArray())); resp.Write("</code></li>"); } resp.Write("<h3>Cookies</h3>"); foreach (var kv in req.Cookies) { resp.Write("<li>«"); resp.Write(kv.Key); resp.Write("»<br/><code>"); resp.Write(kv.Value.ToString()); resp.Write("</code></li>"); } // TODO: Request body? resp.Write("</ul>"); resp.Write("</body>"); resp.Write("</html>"); return resp.ResultTask; }); }