我是靠谱客的博主 粗犷微笑,这篇文章主要介绍.NETCore添加区域Area代码实例解析,现在分享给大家,希望可以做个参考。

一,如下图

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

三,添加路由

复制代码
1
2
3
4
5
6
7
8
9
10
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?}"); });

四,添加控制器

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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"; } } }

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持靠谱客。

最后

以上就是粗犷微笑最近收集整理的关于.NETCore添加区域Area代码实例解析的全部内容,更多相关内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(134)

评论列表共有 0 条评论

立即
投稿
返回
顶部