public void Configuration(IAppBuilder builder) { var xx = default(ArraySegment<byte>); // 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.RunDirect((req, res) => { res.ContentType = "text/plain"; res.End("Hello from " + req.PathBase + req.Path); }); // a route may also be added for a given builder method. // this can also be done from global.asax RouteTable.Routes.AddOwinRoute("wilson-async", x => x.UseShowExceptions().UseContentType("text/plain").Run(Wilson.AsyncApp())); // a route may also be added for a given builder method. // this can also be done from global.asax RouteTable.Routes.AddOwinRoute("wilson", 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.RunDirect((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>") .Write("<head><title>Hello world</title></head>") .Write("<body>") .Write("<p>Hello world!</p>") .Write("<ul>"); resp.Write("<h3>Environment</h3>"); foreach (var kv in req) { if (kv.Value is IDictionary<string, IEnumerable<string>>) { resp.Write("<li>«") .Write(kv.Key) .Write("»<br/><ul>"); foreach (var kv2 in kv.Value as IDictionary<string, IEnumerable<string>>) { resp.Write("<li>«") .Write(kv2.Key) .Write("» = ") .Write(string.Join(", ", kv2.Value.ToArray())) .Write("</code></li>"); } resp.Write("</ul></li>"); } else { resp.Write("<li>«") .Write(kv.Key) .Write("»<br/><code>") .Write(kv.Value.ToString()) .Write("</code></li>"); } } resp.Write("<h3>Cookies</h3>"); foreach (var kv in req.Cookies) { resp.Write("<li>«") .Write(kv.Key) .Write("»<br/><code>") .Write(kv.Value.ToString()) .Write("</code></li>"); } resp .Write("</ul>") .Write("</body>") .Write("</html>") .End(); }); }