nancy框架hosting.self
一、新建控制台应用程序
二、使用NuGet安装nancy.hosting.self
三、监听服务,打开Program.cs文件编辑
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Nancy;
using Nancy.Hosting.Self;
namespace test1
{
class Program
{
static void Main(string[] args)
{
string uri = "http://127.0.0.1:9090";
using(var host = new NancyHost(new Uri(uri)))
{
host.Start();
Console.WriteLine("服务启动:地址 "+uri);
Console.Read();
host.Stop();
}
}
}
}
四、路由编写
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Nancy;
namespace test1.Router
{
public class Router : NancyModule
{
public Router()
{
Get["/"] = _ =>
{
return "hello world";
};
}
}
}