继昨天的Nancy之基于Nancy.Hosting.Aspnet的小Demo后,今天来做个基于Nancy.Hosting.Self的小Demo。关于Self Hosting Nancy,官方文档的介绍如下https://github.com/NancyFx/Nancy/wiki/ ...
继昨天的Nancy之基于Nancy.Hosting.Aspnet的小Demo后,
今天来做个基于Nancy.Hosting.Self的小Demo。
关于Self Hosting Nancy,官方文档的介绍如下
https://github.com/NancyFx/Nancy/wiki/Self-Hosting-Nancy
文档具体的内容我就不一一翻译了,主要是演示从头到尾的一个过程,然后看看Nancy.Hosting.Self的源码
一、新建一个控制台应用程序(Console Application)
二、通过NuGet添加我们需要的Nancy包
这里我们可以直接添加Nancy.Hosting.Self,添加这个会顺带添加Nancy。
到这里我们的基本工作就KO了。
三、打开Program.cs,开始写代码了
1 class Program 2 { 3 static void Main(get='_blank'>string[] args) 4 { 5 using (var nancySelfHost = new NancyHost(new Uri("http://localhost:8888/"))) 6 { 7 nancySelfHost.Start(); 8 Console.WriteLine("NancySelfHost已启动。。"); 9 try10 {11 Console.WriteLine("正在启动 http://localhost:8888/ ");12 System.Diagnostics.Process.Start("http://localhost:8888/");13 Console.WriteLine("成功启动 http://localhost:8888/ ");14 }15 catch (Exception)16 {17 }18 Console.Read();19 }20 Console.WriteLine("http://localhost:8888 已经停止 \n NancySelfHost已关闭。。"); 21 }22 }
提示的居然是没有找到视图!!再细细看一下就会发现问题了。Root path!!!!
六、把这个demo放到linux下看看在 /var/www/ 下面新建一个文件夹 mkdir nancydemo执行 mono SelfHostingDemo.exe趁着时间还早,看看Nancy.Hosting.Self的内部实现,源码地址:还记得否?我们的Program.cs中有用到这个类----NancyHost
原标题:Nancy之基于Nancy.Hosting.Self的小Demo
关键词:
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们:
admin#shaoqun.com
(#换成@)。