How to do it...

  1. Right-click on the solution in yourSolution Explorer and click on Open Folder in File Explorer. You will notice that you have a folder called src. Click into this folder and click on the AspNetCore sub-folder inside it:
  1. Comparing the contents of the AspNetCore folder and the Solution Explorer in Visual Studio will show you that they are virtually the same. This is because in ASP.NET Core, the Windows file system determines the solution in Visual Studio:
  1. In the Windows file explorer, right-click on the Startup.cs file and edit it in Notepad. You will see the following code in Notepad:
        using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;

namespace AspNetCore
{
public class Startup
{
// This method gets called by the runtime. Use this method
to add services to the container.
// For more information on how to configure your application,
visit https://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{
}

// This method gets called by the runtime. Use this method
to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app,
IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.AddConsole();

if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}

app.Run(async (context) =>
{
await context.Response.WriteAsync("Hello World!");
});
}
}
}
  1. Still in Notepad, edit the line that reads await context.Response.WriteAsync("Hello World!"); and change it to read await context.Response.WriteAsync($"The date is {DateTime.Now.ToString("dd MMM yyyy")}");. Save the file in Notepad and go to the browser and refresh it. You will see that the changes are displayed in the browser without me having to edit it in Visual Studio at all. This is because (as mentioned earlier) Visual Studio uses the file system to determine the project structure and ASP.NET Core detected the changes to the Startup.cs file and automatically recompiled it on the fly:
  1. Looking at the Solution Explorer a little more in detail, I want to highlight some of the files in the project. The wwwroot folder will represent the root of the website when hosted. It is here that you will place static files such as images, JavaScript, and CSS style sheet files. Another file of interest is the Startup.cs file, which essentially replaces the Global.asax file. It is here in the Startup.cs file that you can write code to execute when your ASP.NET Core application starts up:
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.21.46.78