【发布时间】:2017-08-30 18:09:45
【问题描述】:
我正在研究“Microsoft.AspNetCore.Mvc”:“1.1.2”
我的项目文件夹结构如下
startup.cs 中的代码如下
当我运行我的项目时,我没有被重定向到索引页面。它显示 404 错误。 我是否缺少任何设置?
【问题讨论】:
-
我发现这个答案已经解决了,你试试this?
标签: asp.net-core asp.net-core-mvc
我正在研究“Microsoft.AspNetCore.Mvc”:“1.1.2”
我的项目文件夹结构如下
startup.cs 中的代码如下
当我运行我的项目时,我没有被重定向到索引页面。它显示 404 错误。 我是否缺少任何设置?
【问题讨论】:
标签: asp.net-core asp.net-core-mvc
你的 url 应该有这个模式(由于你的路由配置):
http://localhost:your_port_number/area_name
当您运行您的应用程序时,您的 url 模式是:
http://localhost:your_port_number
url中没有区域名称。
你应该在url中指定区域Admin,因为你没有默认区域并且你得到404 Not Found,所以你的url应该是这样的:
http://localhost:your_port_number/Admin
或
您可以在app.UseMvc() 中为Area 设置默认值:
routes.MapRoute("adminRoute", "{area=Admin}/{controller=Admin}/{action=Index}/{id?}");
现在默认情况下,您使用控制器名称 Admin 和操作名称 Index 调用区域 Admin 中的端点。
【讨论】: