- Hands-On Full:Stack Web Development with ASP.NET Core
- Tamir Dresher Amir Zuker Shay Friedman
- 168字
- 2021-06-10 19:37:25
Adding MVC to ASP.NET Core
ASP.NET MVC Core does not work by default in ASP.NET Core applications. You must enable it within the code before using it. To do so, follow these steps:
- Open the Startup.cs file.
- Locate the ConfigureServices method and add the highlighted line to it:
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
}
This tells ASP.NET Core to add MVC to the available services. Pay attention — this is not enough for MVC to work, since it needs to be configured first.
- Locate the Configure method and add the highlighted code to it:
public void Configure(IApplicationBuilder app, IHostingEnvironment
env)
{
app.UseStaticFiles();
app.UseMvcWithDefaultRoute();
}
This instructs ASP.NET Core to use the service we added in the ConfigureServices method. In addition, it has a basic configuration for the MVC router. We will discuss ASP.NET Core MVC routing later in this chapter in the Routing section.
By now, you should have ASP.NET MVC configured and ready to run. To see it in action, continue to the next section, Controllers.
推薦閱讀
- 微商之道
- 數字烏托邦
- 通信簡史:從信鴿到6G+
- Getting Started with Grunt:The JavaScript Task Runner
- 城市治理一網統(tǒng)管
- Microsoft Dynamics CRM 2011 Applications(MB2-868) Certification Guide
- 6G新技術 新網絡 新通信
- 網管工具使用與技巧大全
- 通信十年:擁抱互聯網
- 深入理解OpenStack Neutron
- AIoT應用開發(fā)與實踐
- 移動物聯網:商業(yè)模式+案例分析+應用實戰(zhàn)
- 云計算技術與標準化
- Intelligent Mobile Projects with TensorFlow
- 從物聯到萬聯:Node.js與樹莓派萬維物聯網構建實戰(zhàn)