Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Sample Applicaiton Using OWIN/Katana

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 762
    Comment on it

    Sample Application using OWIN/Katana

    OWIN stands for Open Web Interface for .Net. It is a interface between web application and web server. It is used to decouple server and application.

    Steps to create simple application-:

    1)Open Visual studio navigate to File->New->Web site->Asp.Net Empty Web Site.

    2)Now Right click on solution and choose "Manage NuGet Packages for Solutions" then install-:

    a)Microsoft.Owin.Host.SystemWeb

    b)Nancy.Owin

    First way

    public class Startup
    {
        public void Configuration(IAppBuilder appbuilder)
        {
            appbuilder.Run(StartMethod);
        }
    
        public Task StartMethod(IOwinContext context)
        {
            context.Response.ContentType = "text/plain";
            return context.Response.WriteAsync("Hello World");
        }
    }
    

    Create a class called Startup. Now define a configuration method and from this method run your start method. Content-type->Define type of content here we want to print simple text thatswhy type is "text/plain".

    Second way Using Nancy framework

      public class Startup
        {
            public void Configuration(IAppBuilder appbuilder)
            {
                appbuilder.UseNancy();
            }
    
        }
        public class MyModule : NancyModule
        {
            public MyModule()
            {
                Get["/"] = x =>
                {
                var model = new { title = "My first Owin Nancy Application", body = "Hello world" };
                    return View["MyView", model];
                };
            }
        }
    

    Here, we have created a module named MyModule which is inheriting NancyModule. In this module we have created "Get" method in which we have created a model object with properties title and body. Now, we are returning View["MyView",model], which will search for view named "MyView" and "model" act as model for that view.

    Now,create a html page "MyView.html".

    <!DOCTYPE html>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>@Model.title</title>
    </head>
    <body>
        @Model.body
    </body>
    </html>
    

    When we run this html page, We will see title of page as "My first Owin Nancy Application" and body as "Hello world".


    Read More

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: