Get Started!

Hello World

The simplest Handler

Here's a simple "Hello World" HTTPHandler class.

using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.SessionState;

using Net4orce.Core;
using Net4orce.Core.Canvas.Meta;

namespace Example
{
  public class HelloWorld : HandlerBase, IRequiresSessionState 
  {

    public override void initialize(HttpContext context, AsyncCallback cb, object extraData)
    {
      base.initialize(context, cb, extraData);
      oOpperation = new Operation(cb, context, extraData);
    }

  }

  public class Operation : HandlerOpBase
  {
    public Operation(AsyncCallback cb, HttpContext context, Object state) 
              : base(cb, context, state) { }

    public override void Handle(object oExtraData) {
      oResponse.ClearHeaders();

      oResponse.AddHeader("Content-Type", "text/plain");

      oResponse.Write(
        "Hello, World"
      );

      Close();
    }
  }
} 

Register the class

To register the handler use the follwoing, in your Application class :

CanvasApp.RegisterHandlerRoute(
  "hello-world",
  "hello.txt",
  new Handlers.Download()
);

Naviagte to /hello.txt and you'll see the result.

Add a Param

Lets add a name parameter, and read the value via getParam :

public class Operation : HandlerOpBase
{
  public Operation(AsyncCallback cb, HttpContext context, Object state) 
            : base(cb, context, state) { }

  public override void Handle(object oExtraData) {
    oResponse.ClearHeaders();

    oResponse.AddHeader("Content-Type", "text/plain");

    var name = "World";
    getParam( "name", out name );

    oResponse.Write(
      "Hello, " + name
    );

    Close();
  }
}

Now navigate to /hello.txt?name=NetCanvas.