MVC 6-区域路由未重定向到配置的页面 [英] MVC 6 - Areas Routing is not redirecting to the configured page

查看:114
本文介绍了MVC 6-区域路由未重定向到配置的页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究"Microsoft.AspNetCore.Mvc":"1.1.2"

I am working on "Microsoft.AspNetCore.Mvc": "1.1.2"

我的项目文件夹结构如下

My project folder structure is as below

startup.cs中的代码在下面

Code in startup.cs is below

运行项目时,我不会重定向到索引页面.它显示404错误. 我缺少任何设置吗?

When I run my project I am not redirected to the index page. It shows 404 Error. Am I missing any setting?

推荐答案

您的网址应具有以下格式(由于您的路由配置):

Your url should have this pattern (due to your routes configuration):

http://localhost:your_port_number/area_name

运行应用程序时,您的网址格式为:

When you run your application your url pattern is:

http://localhost:your_port_number

URL中没有区域名称.

There is no area name in the url.

您应该在url中指定区域Admin,因为您没有默认区域,并且会得到404 Not Found,因此您的url应该像这样:

You should specify the area Admin in url, because you don't have default area and you get 404 Not Found, so your url should be like this:

http://localhost:your_port_number/Admin

OR

您可以在app.UseMvc()中为Area设置默认值:

You can set default value for Area in app.UseMvc():

routes.MapRoute("adminRoute", "{area=Admin}/{controller=Admin}/{action=Index}/{id?}");

现在默认情况下,您在区域Admin中使用控制器名称Admin和操作名称Index调用端点.

Now by default you call endpoint in area Admin with controller name Admin and action name Index.

这篇关于MVC 6-区域路由未重定向到配置的页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆