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