Nancy's opening

Source: Internet
Author: User

Nancyfx is a lightweight Web Development Framework (based on . NET ), I use it, mostly it can not depend on IIS (because my current project is lightweight BS framework), you can Selfhost .

Nancy The URL is: http://nancyfx.org/

in order to VS in the rapid development, you can download its project template,: http://sidewaffle.com/

I'm using it. VS2015 , after downloading the installation, you can create Nancy of the Selfhost projects, such as:

650) this.width=650; "title=" Nancy01001.png "style=" Float:none; "alt=" wkiom1c5kmkdziioaadwz5_1m78593.png "src=" http ://s3.51cto.com/wyfs02/m02/80/29/wkiom1c5kmkdziioaadwz5_1m78593.png "/>


After you finish creating the project

650) this.width=650; "title=" Nancy01002.png "style=" Float:none; "alt=" wkiol1c5kaqqoilvaabbuah3oj4061.png "src=" http ://s3.51cto.com/wyfs02/m00/80/26/wkiol1c5kaqqoilvaabbuah3oj4061.png "/>

There are four places to see.

1. Program.cs

Using system;using nancy.hosting.self;namespace testselfhostweb{    class  Program    {        static void  Main (String[] args)         {             var uri =                 new uri ("http://localhost:3579");              using  (Var host = new nancyhost (URI))             {                 host. Start ();                 Console.WriteLine ("Your application is running on  " + uri);                 console.writeline ("Press any [enter] to close the host.");                  Console.ReadLine ();            }         }    }}


Obviously, it's Selfhost The main code, very simple, is to open a native 3579 port, which is used to receive Browser request, note that you want to start as an administrator at startup.

2. IndexModule.cs

using nancy;namespace  Testselfhostweb.modules{    public class indexmodule : nancymodule     {        public indexmodule ()          {             get["/"] = parameters =>             {                return  view["Index"];            };         }    }} 

is also Nancy relatively cool place, as long as the inheritance Nancymodule can be mounted automatically on the Host in which Browser Enter the correct URL you can access it. The current get corresponds to a get request, which naturally has Other requests such as post.

3. index.cshtml

<! Doctype html>

It's a standard . Razor page, with Asp.netmvc in the Razor is the same, not much to say.

4. Bootstrapper.cs

Using Nancy;namespace testselfhostweb{public class Bootstrapper:defaultnancybootstrapper {//the boot Strapper enables you-reconfigure the composition of the framework,//By overriding the various methods and prop        Erties. For more Information Https://github.com/NancyFx/Nancy/wiki/Bootstrapper}}
is the Web startup portal, a bit like the global file in ASP., you can rewrite some class members.

you can run now. VS , directly F5 start the program, or you can find the execution program to run as an administrator, and then Browser Enter the local ID and ports, the effect is as follows:

650) this.width=650; "title=" Nancy01003.png "src=" http://s3.51cto.com/wyfs02/M02/80/26/ Wkiol1c5ltstp2z0aablmykttr8773.png "alt=" Wkiol1c5ltstp2z0aablmykttr8773.png "/>

This article is from the "Gui Suewei" blog, make sure to keep this source http://axzxs.blog.51cto.com/730810/1773988

Nancy's opening

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.