When you use ASP. NET to create a web project, you can select either the web application type of ASP. NET or the web form application type, or the MVC mode. Today we will introduce Nancy, A. NET Framework that is completely different from these types. The Nancy framework can be used to process Delete, get, Head, options, post, put, and patch requests, and uses a simple, elegant and DSL processing method.
You can learn more about: http://nancyfx.org/
1. Install the nuget Plugin in monodevelop 4.0
Install addin --- nuget (about nuget) of monodevelop before installing Nancy ).
Open monodevelop and select "tool" = "add in Manager ". In the displayed dialog box, select the "galley" tab and select "manage repositories" from the drop-down list ". Then add an installation source.
For monodevelop3.0.5, use the following address:
http://mrward.github.com/monodevelop-nuget-addin-repository/3.0.5/main.mrep
For monodevelop 4.0, use the following address:
http://mrward.github.com/monodevelop-nuget-addin-repository/4.0/main.mrep
After adding the plug-in, Click Refresh to see that the nuget plug-in is already in the list:
Click the Install button under the Right to install nuget into monodevelop.
2. Create a test project and use the Nancy framework.
The Nancy framework can be hosted in the ASP. NET web framework or MVC framework. This article uses the host of the MVC job Nancy.
Create a new project. Here we will name the solution firstnancy and the web Project firstnancy. Web. After the solution is created, you can manage the menu of nuget.
In the pop-up window, enter Nancy in the search box and add Nancy and Nancy. hosting. two ASPnet components will be added to the solution, and two references will be automatically added to the project: Nancy. DLL and Nancy. hosting. ASPnet. DLL.
In addition to adding two references to Nancy, the add operation also modifies the web. in the httphandlers module of config, You have to manually modify it, comment out the httphandlers of the previous MVC, and finally change it to the following code:
In addition, remove the routing code in global. asax,
public class MvcApplication : System.Web.HttpApplication{public static void RegisterRoutes (RouteCollection routes){//routes.IgnoreRoute ("{resource}.axd/{*pathInfo}");////routes.MapRoute (//"Default",//"{controller}/{action}/{id}",//new { controller = "Home", action = "Index", id = "" }//);}public static void RegisterGlobalFilters (GlobalFilterCollection filters){filters.Add (new HandleErrorAttribute());}protected void Application_Start (){AreaRegistration.RegisterAllAreas ();RegisterGlobalFilters (GlobalFilters.Filters);RegisterRoutes (RouteTable.Routes);}}
Create a defamodule module. CS module with the following code:
using System;using Nancy;namespace FirstNacy.Web{public class DefaultModule : NancyModule{public DefaultModule (){Get ["/"] = paramaters =>{return "
The module here inherits from the nancymodule and declares two routes in the defaultmodule constructor. Rules in these frameworks can be found on the Nancy website. After the project is created, you can generate it to view the display effect of the test project, as shown below:
Access the page with parameters, as shown below:
Iii. Considerations for running the ASP. net mvc project in Mono 3.0
Put the above application on the Ubuntu server, and an error is reported. The reason is that the system. Web. webpages assembly cannot be found.
Later, I found the blog "Run ASP under mono 3.0" by Dr. Zhang Shanyou. net 4 website after the idea, in the site web. the system. web. the webpages configuration is successful.
<assemblies> ... <add assembly="System.Web.WebPages, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" /> ... </assemblies>
All versions with version 1.0.0.0 must be changed to 2.0.0.0.
<appSettings> <add key="webpages:Version" value="2.0.0.0" /> ... </appSettings>
The Nancy framework has many features worth studying. This article is just a simple example. For details about the framework rules, see the documentation on the Nancy website.
Refer:
Build a distributed development system using the lightweight frameworks Nancy and simple. Data (1)
Idea about running ASP. NET 4 website in Mono 3.0