您现在的位置是:网站首页> 编程资料编程资料
.NETCore添加区域Area代码实例解析_实用技巧_
2023-05-24
275人已围观
简介 .NETCore添加区域Area代码实例解析_实用技巧_
一,如下图

二,构建好框架,将不必要的包删掉

三,添加路由
app.UseEndpoints(endpoints => { endpoints.MapControllerRoute( name: "default", pattern: "{controller=Home}/{action=Index}/{id?}"); endpoints.MapAreaControllerRoute( name: "areas", "areas", pattern: "{area:exists}/{controller=Home}/{action=Index}/{id?}"); });四,添加控制器
using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; namespace NLD.HouTai.Areas.Api.Controllers { [ApiController] [Area("API")] [Route("API/[controller]/[action]")] public class UserController : ControllerBase { [HttpGet] public string Get() { return "Get"; } } }以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
您可能感兴趣的文章:
相关内容
- 详解ASP.NET Core端点路由的作用原理_实用技巧_
- .Net Core 2.2升级3.1的避坑指南(小结)_实用技巧_
- 通过Windows Visual Studio远程调试WSL2中的.NET Core Linux应用程序的方法_实用技巧_
- .Net Core如何对MongoDB执行多条件查询_实用技巧_
- 详细分析ASP.NET Razor之C# 变量_实用技巧_
- 详解ASP.NET Razor 语法_实用技巧_
- [Asp.Net Core]提高开发效率的方法_实用技巧_
- 使用vs2019加.net core 对WeiApi的创建过程详解_实用技巧_
- [Asp.Net Core]用Blazor Server Side实现图片验证码_实用技巧_
- 基于.NET的FluentValidation数据验证实现_实用技巧_
