官术网_书友最值得收藏!

Changing the Startup class name

The name of the Startup class is a convention of ASP.NET Core applications. It is recommended to leave it as it is to make the code clearer for colleagues. However, there are a few situations where you are required to use a different name for the Startup class—for example, when Startup is already a class in your application but is responsible for an entirely different task than initializing ASP.NET Core.

On such occasions, open the Program class file, located in the root folder under Program.cs, and locate the CreateWebHostBuilder method. It should look similar to the following:

 public static IWebHostBuilder CreateWebHostBuiler(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>();

In order to point ASP.NET Core to a different class name, for example, to CustomStartup, change the UseStartup<Startup>() line to UseStartup<CustomStartup>:

public static IWebHostBuilder CreateWebHostBuiler(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>();
If you're using different Startup classes for each environment, changing the name will affect the suffix. For example, instead of StartupDevelopment, ASP.NET Core will look for a CustomStartupDevelopment class.
主站蜘蛛池模板: 达州市| 观塘区| 岳西县| 广州市| 阿鲁科尔沁旗| 高淳县| 平利县| 长丰县| 广州市| 固原市| 南昌县| 鹿邑县| 沾益县| 涪陵区| 海安县| 西充县| 梓潼县| 新源县| 岳西县| 韶山市| 望城县| 韶山市| 舟山市| 宁都县| 榆社县| 勃利县| 托克托县| 肃南| 临邑县| 鄂伦春自治旗| 龙海市| 冀州市| 玉树县| 遵义市| 高密市| 扎鲁特旗| 临洮县| 武城县| 娱乐| 渝中区| 化隆|