[英]Area routing in ASP.NET Core 5.0
Using ASP.NET Core 5.0 MVC, the application is using an area named Counselor
with a HomeController
and Index
action.使用 ASP.NET Core 5.0 MVC,该应用程序正在使用一个名为
Counselor
的区域以及HomeController
和Index
操作。
One link is added in Layout.cshtml
to counselor.在
Layout.cshtml
中添加了一个指向顾问的链接。
Also, the endpoint is already added the endpoint in Startup.cs此外,端点已添加到 Startup.cs 中的端点
The problem:问题:
The link created is wrong ( localhost:44308/?area=Counselor
) but it should be localhost:44308/Counselor/Home/Index
创建的链接是错误的(
localhost:44308/?area=Counselor
)但它应该是localhost:44308/Counselor/Home/Index
Since I had this problem today too, this is how I solved the problem:由于我今天也遇到了这个问题,所以这就是我解决问题的方法:
Make sure you have SSL enabled in your project settings (I do not know why it should be enabled) see image here .确保您在项目设置中启用了 SSL(我不知道为什么要启用它)请参见此处的图片。
Try this code in Startup.cs:在 Startup.cs 中尝试此代码:
endpoints.MapAreaControllerRoute(
name: "Counselor",
areaName: "Counselor ",
pattern: "Counselor/{controller=Home}/{action=Index}/{id?}");
namespace Project.Controllers
{
[Area("Counselor")]
public class HomeController : Controller
{
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.