.NET Core - Basic Information

.NET Core is an absolutely free, cross platform and open source s\w framework for Windows, Linux and macOS

Introduction

.NET Core is an absolutely free, cross-platform, and open source software framework for Windows, Linux, and macOS. It is redesigned from scratch to quickly work with flexibility and with different platforms.

.NET Core includes the MVC framework, which now merges the features of MVC and Web API into a single framework. Today, this framework is not based on System.Web.dll. Instead, it is based on small and relevent NuGet packages.

Below are some important and useful features,

To load JSON file (appsetting.json etc.), we can write the following script in startup.cs file.
  1. public Startup() {   
  2.          var builder = new ConfigurationBuilder()   
  3.             .AddJsonFile("AppSettings.json");   
  4.          Configuration = builder.Build();   
  5.       }    
  6. app.Run(async (context) => {   
  7.       var msg = Configuration["message"];   
  8.       await context.Response.WriteAsync(msg);   
  9.    });    

If you want to use a welcome page, use this code.

  1. // This method will call by the runtime.    
  2.   
  3. // To configure the HTTP request pipeline.   
  4.   
  5. public void Configure(IApplicationBuilder app) {   
  6.    app.UseIISPlatformHandler();   
  7.    app.UseWelcomePage();    
  8.      
  9.    app.Run(async (context) => {   
  10.       var msg = Configuration["message"];   
  11.       await context.Response.WriteAsync(msg);   
  12.    });    
  13. }  
Page run time info can be found using this script.
  1. public void Configure(IApplicationBuilder app) {   
  2.    app.UseIISPlatformHandler();   
  3.    app.UseRuntimeInfoPage();    
  4.      
  5.    app.Run(async (context) => {   
  6.       var msg = Configuration["message"];   
  7.       await context.Response.WriteAsync(msg);   
  8.    });    
  9. }  

Note
“/runtimeinfo” at the end of your URL. You will now see a page that is produced by that runtime info page's middleware. [More resources : https://www.tutorialspoint.com/asp.net_core/asp.net_core_middleware.htm ]

middleware

UseDeveloperExceptionPage 

  1. public void Configure(IApplicationBuilder app) {   
  2.    app.UseIISPlatformHandler();    
  3.    app.UseDeveloperExceptionPage();   
  4.    app.UseRuntimeInfoPage();    
  5.      
  6.    app.Run(async (context) => {   
  7.       throw new System.Exception("Throw Exception");   
  8.       var msg = Configuration["message"];   
  9.       await context.Response.WriteAsync(msg);   
  10.    });    
  11. }  

To use static files,

Microsoft.AspNet.StaticFiles 

  1. public void Configure(IApplicationBuilder app) {   
  2.          app.UseIISPlatformHandler();    
  3.          app.UseDeveloperExceptionPage(); app.UseRuntimeInfoPage();   
  4.          app.UseStaticFiles();   
  5.            
  6.          app.Run(async (context) => {   
  7.             throw new System.Exception("Throw Exception");   
  8.             var msg = Configuration["message"];   
  9.             await context.Response.WriteAsync(msg);   
  10.          });   
  11.       }    
To use default files,
  1. public void Configure(IApplicationBuilder app)  {   
  2.    app.UseIISPlatformHandler();    
  3.    app.UseDeveloperExceptionPage();   
  4.      
  5.    app.UseRuntimeInfoPage();    
  6.    app.UseDefaultFiles();   
  7.      
  8.    app.Run(async (context) => {   
  9.       var msg = Configuration["message"];   
  10.       await context.Response.WriteAsync(msg);   
  11.    });    
  12. }  

If you want to use DefaultFiles and StaticFiles, then you need another piece of middleware that is inside the Microsoft.aspnet.staticfiles.

NuGet package; namely FileServer middleware, includes the Default Files and the Static Files.
  1. public void Configure(IApplicationBuilder app) {   
  2.    app.UseIISPlatformHandler();    
  3.    app.UseDeveloperExceptionPage();   
  4.      
  5.    app.UseRuntimeInfoPage();    
  6.    app. UseFileServer();    
  7.      
  8.    app.Run(async (context) => {   
  9.       var msg = Configuration["message"];   
  10.       await context.Response.WriteAsync(msg);   
  11.    });   
  12. }  
If you want to use dynamic connection string please refer to this blog.

To setup MVC framework in our empty project, please refer to this link.