.NET Core

.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 relevant NuGet packages.

Below are some important and useful features,

To load JSON file (appsetting.json etc.), we can write the following script in a startup.cs file.

public Startup() {   
         var builder = new ConfigurationBuilder()   
            .AddJsonFile("AppSettings.json");   
         Configuration = builder.Build();   
      }    
app.Run(async (context) => {   
      var msg = Configuration["message"];   
      await context.Response.WriteAsync(msg);   
   });

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

// This method will call by the runtime.    
  
// To configure the HTTP request pipeline.   
  
public void Configure(IApplicationBuilder app) {   
   app.UseIISPlatformHandler();   
   app.UseWelcomePage();    
     
   app.Run(async (context) => {   
      var msg = Configuration["message"];   
      await context.Response.WriteAsync(msg);   
   });    
}

Page run time info can be found using this script.

public void Configure(IApplicationBuilder app) {   
   app.UseIISPlatformHandler();   
   app.UseRuntimeInfoPage();    
     
   app.Run(async (context) => {   
      var msg = Configuration["message"];   
      await context.Response.WriteAsync(msg);   
   });    
}  

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]

UseDeveloperExceptionPage

public void Configure(IApplicationBuilder app) {   
   app.UseIISPlatformHandler();    
   app.UseDeveloperExceptionPage();   
   app.UseRuntimeInfoPage();    
     
   app.Run(async (context) => {   
      throw new System.Exception("Throw Exception");   
      var msg = Configuration["message"];   
      await context.Response.WriteAsync(msg);   
   });    
}

To use static files,

Microsoft.AspNet.StaticFiles

public void Configure(IApplicationBuilder app) {   
         app.UseIISPlatformHandler();    
         app.UseDeveloperExceptionPage(); app.UseRuntimeInfoPage();   
         app.UseStaticFiles();   
           
         app.Run(async (context) => {   
            throw new System.Exception("Throw Exception");   
            var msg = Configuration["message"];   
            await context.Response.WriteAsync(msg);   
         });   
      }

To use default files,

public void Configure(IApplicationBuilder app)  {   
   app.UseIISPlatformHandler();    
   app.UseDeveloperExceptionPage();   
     
   app.UseRuntimeInfoPage();    
   app.UseDefaultFiles();   
     
   app.Run(async (context) => {   
      var msg = Configuration["message"];   
      await context.Response.WriteAsync(msg);   
   });    
}

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.

 

public void Configure(IApplicationBuilder app) {   
   app.UseIISPlatformHandler();    
   app.UseDeveloperExceptionPage();   
     
   app.UseRuntimeInfoPage();    
   app. UseFileServer();    
     
   app.Run(async (context) => {   
      var msg = Configuration["message"];   
      await context.Response.WriteAsync(msg);   
   });   
}

 

Faisal Pathan

Faisal Pathan is a founder of TheCodeHubs, .NET Project Manager/Team Leader, and C# Corner MVP. He has extensive experience with designing and developing enterprise-scale applications. He has good skills in ASP.NET C#, ASP.NET Core, ASP.NET MVC, AngularJS, Angular, React, NodeJS, Amazon S3, Web API, EPPlus, Amazon MWS, eBay Integration, SQL, Entity Framework, JavaScript, eCommerce Integration like Walmart, Tanga, Newegg, Group-on Store, etc. and Windows services.

Share
Published by
Faisal Pathan

Recent Posts

Testing hk

Testing

2 years ago

Create and Used PIPE in angular

In this article, we have to show Create and Used PIPE in angular

2 years ago

Operation

Testing

2 years ago

Create and Used PIPE in angular

In this article, we have to show Create and Used PIPE in angular

2 years ago

Create and Used PIPE in angular

In this article, we have to show Create and Used PIPE in angular

2 years ago

TETS NEW

test

3 years ago