When you use ASP.net to create a Web project, the general choice is asp.net Web site application type or Web Form application type, otherwise it is the MVC pattern. Today introduces a completely detached from these types. NET Framework--nancy. The Nancy framework can be used to process delete,, OPTIONS, POST, put, and patch requests, and uses a simple, elegant, and DSL approach.
You can learn more on Nancy's website: http://nancyfx.org/
First, install the NuGet plug-in in MonoDevelop 4.0
Before installing Nancy, you need to first install MonoDevelop addin---NuGet (about NuGet).
Open MonoDevelop and select "Tools" = "Add in Manager". In the Pop-up dialog window, select "Galley" tab, and Drop-down to select "Manage repositories". Then add an installation source.
If MonoDevelop3.0.5, please use the following address:
Http://mrward.github.com/monodevelop-nuget-addin-repository/3.0.5/main.mrep
If MonoDevelop 4.0, please use the following address:
Http://mrward.github.com/monodevelop-nuget-addin-repository/4.0/main.mrep
After the addition is complete, click the Refresh button and you can see that the NuGet plugin is already in the list:
When selected, click the Install button at the bottom of the right so that the NuGet is successfully installed into the MonoDevelop.
Second, create a new test project and use the Nancy framework.
The Nancy framework can be hosted in a asp.net web framework or MVC framework. This article will use the MVC task Nancy's host.
To create a new project, I'll name the solution firstnancy and name the WEB project Firstnancy.web. When the solution is new, you can nuget the Management menu
In the pop-up window, enter Nancy in the search box, add Nancy, Nancy.Hosting.Aspnet two components into the solution, and automatically add two references to the project: Nancy.dll and Nancy.Hosting.Aspnet.dll.
In addition to adding two Nancy references, the addition will also modify the httphandlers module in Web.config, at which point you have to manually modify the previous MVC httphandlers annotation, and finally, the following code:
At the same time, remove the routing code from the 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 new DefaultModule.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 Nancymodule and, in the Defaultmodule constructor, declares two routes. The rules in these frameworks can be found at Nancy's website. When you are done, you can build and view the results of the test project as follows:
Access the page with parameters as follows:
Iii. Mono 3.0 Considerations When running the ASP.net MVC project
Put the above application on the Ubuntu server and reported the error. The reason is that the System.Web.WebPages assembly could not be found.
Later found Zhang Shanyu predecessor of the blog "in Mono 3.0 run ASP.net 4 website idea matters", in the site Web.config, modified System.Web.WebPages related configuration, run successfully.
<assemblies> ...
<add assembly= "System.Web.WebPages, version=2.0.0.0, culture=neutral, publickeytoken=31bf3856ad364e35"/>
...
</assemblies>
All with the version number of 1.0.0.0, should be changed to 2.0.0.0
<appSettings>
<add key= "webpages:version" value= "2.0.0.0"/>
...
</appSettings>
The Nancy framework is well worth studying, and this article is just a simple example of a detailed framework rule that can be viewed on Nancy's website.
Reference:
Build a distributed development system using Nancy and Simple.data two lightweight frameworks (i)
Ideas for running ASP.net 4 website under Mono 3.0