There is no startup.cs application in my dotnet core 8 project. The guide I followed includes startup.cs because it is an old version. What should I do?
In the guide, there is CORS disablement, but I do not have startup.cs.
There is no startup.cs application in my dotnet core 8 project. The guide I followed includes startup.cs because it is an old version. What should I do?
In the guide, there is CORS disablement, but I do not have startup.cs.
2
Answers
In .NET Core 3.x and later, there is no
Startup.cs
file by default in ASP.NET Core projects. Instead, you typically configure your application using theProgram.cs
file and theWebHostBuilder
. Here’s a basic example of how you can configure a .NET Core 3.x or later application:In this setup, you can configure services and middleware directly within the
ConfigureServices
andConfigure
methods, respectively. You don’t have a separateStartup.cs
file for this configuration.Since .NET 6 default ASP.NET Core templates use so called minimal hosting model. But you can still use the one with
Startup
– see the .NET Generic Host in ASP.NET Core doc.If you want to follow the new approach the general rule of thumb would be to move everything from
Startup.ConfigureServices
to before building the app (i.e.var app = builder.Build();
) call and usebuilder.Services
andbuidler.Configuration
where appropriate and everything fromStartup.Configure
– after building the app and use theapp
for corresponding calls (check out code generated by the default template).See also: