ASP. NET Core and asp. netcore
ASP. net mvc 6: https://docs.asp.net/en/latest/mvc/index.html
ASP. NET Core: https://docs.asp.net/en/latest/fundamentals/index.html
Cli-samples: https://github.com/aspnet/cli-samples
The following is a summary of my learning process.
Complain!
Microsoft releases candidate versions ......
1: In early March, I started viewing ASP. NET Core and used 2015 to build a test project. Everything is normal and everything is OK. It can be said that there is no problem in one step (I am so happy that I feel like I am going to Heaven)
2: Unfortunately, this week, the project is updated to RC2, and the project package is restored with an error: [Reference (error-see "Error List ")] (lost, angry, furious ......)
3: Search around and make the final. NET cross-platform tour: Upgrade the sample site from ASP. NET 5 RC1 to ASP. NET Core 1.0, Which is overjoyed.
4: dotnet restore updated the package and GG again today.
Question?
I don't have enough brains. Who can give me more than two pounds!
1: After CR2, how do I host the project to IIS or IIS Express?
2: Why do I always report [Reference (error-refer to "Error List") When I right-click to reference-restore a package in 2015 ")], however, it is normal after dotnet restore is used in the command line.
3: Sometimes there will be a [no actions matched the current request] error. What route has been matched successfully, but the request does not match the action? What is this? But after I modify the Startup. cs file again, I can!
............
N: and so on.
Basic Configuration
Time: March 17, 2016 19:05:03
1. Program entry configuration (Program. cs ):
public class Program{ public static void Main(string[] args) { var host = new WebHostBuilder() .UseServer("Microsoft.AspNetCore.Server.Kestrel") .UseContentRoot(Directory.GetCurrentDirectory()) .UseDefaultConfiguration(args) .UseIISPlatformHandlerUrl() .UseStartup<Startup>() .Build(); host.Run(); }}
Note: 3.15 million holidays will
UseApplicationBasePath (Directory. GetCurrentDirectory ())
Change
UseContentRoot (Directory. GetCurrentDirectory ())
I can't figure out why. record it.
2. Start the program (Startup. cs ):
public class Startup{ public void ConfigureServices(IServiceCollection services) { services.AddMvc(); services.AddTransient<Model.Services.StatisticsService>(); } public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) { app.UseMiddleware<artifacts.Middlewares.TimeRecorderMiddleware>(); loggerFactory.AddConsole(LogLevel.Debug); app.UseIISPlatformHandler(); app.UseForwardedHeaders(new ForwardedHeadersOptions { ForwardedHeaders = ForwardedHeaders.All }); app.UseStaticFiles(); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseMvcWithDefaultRoute(); }}
After configuring the entry program and Startup Program, run the command dotnet restore to update the package, and then type dotnet run to enable the self-hosting service.
You can load the page through http: // localhost: 5000 through the default route.
Okay, that's the simple configuration.
Simple process from no website creation
1. Enter cmd in win + R and locate a directory (my directory is D: \ ASP. NET ).
D:\ASP.NET>dotnet newCreated new C# project in D:\ASP.NET.
2. Run the command dotnet new to initialize a simple and basic. net project.
D:\ASP.NET>dotnet restorelog : Restoring packages for D:\ASP.NET\project.json...info : Committing restore...log : Restore completed in 4200ms.NuGet Config files used: D:\ASP.NET\NuGet.Config C:\Users\Administrator\AppData\Roaming\NuGet\NuGet.ConfigFeeds used: https://dotnet.myget.org/F/dotnet-core/api/v3/index.json https://api.nuget.org/v3/index.json
3. Enter the startup command dotnet run to start the program.
D:\ASP.NET>dotnet runCompiling ASP.NET for DNXCore,Version=v5.0Compilation succeeded. 0 Warning(s) 0 Error(s)Time elapsed 00:00:03.2201958Hello World!
4. It's easy to get started.
// Program file public class Program {public static void Main (string [] args) {Console. WriteLine ("Hello World! ");}}
Note: the directory structure is:
D:.│ NuGet.Config│ Program.cs│ project.json│ project.lock.json│├─bin│ └─Debug│ └─dnxcore50│ │ ASP.NET.dll│ │ ASP.NET.pdb│ ││ └─win7-x64│ ASP.NET.deps│ ASP.NET.dll│ ASP.NET.exe│ ASP.NET.pdb│ hostpolicy.dll│└─obj └─Debug └─dnxcore50 dotnet-compile-csc.rsp dotnet-compile.assemblyinfo.cs dotnet-compile.rsp
Because dotnet new creates a console application, only one Program file exists.
If you need to build a WEB application, you need to add the Startup. cs file (above), and then use WebHostBuilder to host in Program. cs.