Zoeken…


Invoering

Wat is Katana? Katana is een set open source componenten voor het bouwen en hosten van op OWIN gebaseerde webapplicaties, onderhouden door de Microsoft Open Technologies Group. Katana biedt een implementatie van de OWIN-specificatie en wordt in feite gebruikt in een toenemend aantal ASP.NET-projectsjablonen . Bovendien biedt Katana een breed scala aan kant-en-klare middleware-componenten, klaar voor gebruik in een OWIN-gebaseerde applicatie.

Voorbeeld

Basic KatanaConsole-toepassing

namespace KatanaConsole
{
    // use an alias for the OWIN AppFunc:
    using AppFunc = Func<IDictionary<string, object>, Task>;
 
    class Program
    {
        static void Main(string[] args)
        {
            WebApp.Start<Startup>("http://localhost:8080");
            Console.WriteLine("Server Started; Press enter to Quit");
            Console.ReadLine();
        }
    }
 
    public class Startup
    {
        public void Configuration(IAppBuilder app)
        {
            var middleware = new Func<AppFunc, AppFunc>(MyMiddleWare);
            app.Use(middleware);
        }
 
        public AppFunc MyMiddleWare(AppFunc next)
        {
            AppFunc appFunc = async (IDictionary<string, object> environment) =>
            {
                // Do something with the incoming request:
                var response = environment["owin.ResponseBody"] as Stream;
                using (var writer = new StreamWriter(response))
                {
                    await writer.WriteAsync("<h1>Hello from My First Middleware</h1>");
                }
                // Call the next Middleware in the chain:
                await next.Invoke(environment);
            };
            return appFunc;
        }
    }
}


Modified text is an extract of the original Stack Overflow Documentation
Licentie onder CC BY-SA 3.0
Niet aangesloten bij Stack Overflow