. NET Cross-platform: use VIM handwritten ASP. 5 MVC program under MAC command line

Source: Internet
Author: User

Yesterday on the MAC started writing a simplest ASP. NET 5 program, directly in the Startup.cs through the Response.writeasync () output response content, see. NET Cross-platform: Follow the error message step-by-step on your Mac to write the ASP. 5 program.

Today followed yesterday's code, using Vim to hand-write one of the simplest ASP. NET 5 MVC programs.

Create the Controllers folder first:

mkdir Controllers && CD $_

Then create the HomeController.cs file:

Enter the following code in VIM and exit only:

using MICROSOFT.ASPNET.MVC; namespace hellocnblogs{    publicclass  homecontroller:controller    {          public Iactionresult Index ()        {            return Content ("Hello, cnblogs! --ASP. 5 MVC");        }    

Then use VIM to open the Startup.cs file to add MVC-related code:

using Microsoft.AspNet.Builder; using Microsoft.Framework.DependencyInjection; namespace hellocnblogs{    publicclass  Startup    {         public  void  Configure (Iapplicationbuilder app)        {            app. Usemvcwithdefaultroute ();        }          Public void configureservices (iservicecollection services)        {            services. Addmvc ();     }}}

And then just add the MVC reference in Project.json with Vim.

"Dependencies": {        "Kestrel": "1.0.0-*",        "MICROSOFT.ASPNET.MVC": "6.0.0-*"    }

Next, start running the simplest ASP. NET 5 MVC program.

To install the referenced package first:

DNU Restore

Then run the program:

Dnx. Kestrel

Run successfully!

Started

To access http://localhost:8080/in a browser, the following responses are available:

Hello, cnblogs!. --ASP. NET 5 MVC

Get!

With this handwritten code ASP. NET 5 MVC code, you get the minimum configuration to run a simple ASP. NET 5 MVC Program:

In addition to the Controller, the configuration in Project.json is as follows:

{"    commands": {        "kestrel": "Microsoft.AspNet.Hosting--server Kestrel--server.urls http://localhost:8080"    },    "dependencies": {        "Kestrel": "1.0.0-*", "        Microsoft.AspNet.Mvc": "6.0.0-*"    },    " Frameworks ": {        " Dnxcore50 ": {}}    }

The code in Startup.cs is as follows:

using Microsoft.AspNet.Builder; using Microsoft.Framework.DependencyInjection; namespace hellocnblogs{    publicclass  Startup    {         public  void  Configure (Iapplicationbuilder app)        {            app. Usemvcwithdefaultroute ();        }          Public void configureservices (iservicecollection services)        {            services. Addmvc ();     }}}

. NET Cross-platform: Use the VIM handwritten ASP. 5 MVC program on the MAC command line

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.