asp.net-mvc - MVC and areas of razor pages in same project .net core
问题描述
I have an area in MVC project. In the area section I have razor pages project in .NET Core. How can I map both routes? When I visit https://localhost:44361/
then main project should be run and if I visit https://localhost:44361/backend
then the area of razor pages should be run.
解决方案
Because Razor pages is using folder-based routing as default, you may create folder Pages/Backend, and use a standard setup as shown below.
The same solution using areas: Create folder Areas/Backend/Pages and use the setup shown below.
In Startup#ConfigureServices
services.AddControllers();
services.AddRazorPages();
In Startup#Configure
app.UseEndpoints(endpoints =>
{
endpoints.MapRazorPages();
endpoints.MapControllers();
});
Both approaches above are verified by creating a MVC-app and added support for Razor pages by adding services.AddRazorPages();
and endpoints.MapRazorPages();
.
More information about areas: https://docs.microsoft.com/en-us/aspnet/core/mvc/controllers/areas?view=aspnetcore-5.0#areas-with-razor-pages
推荐阅读
- linux - 使用 gstreamer 混合多个 rtp 音频流
- java - 使用 Spans 获取 EditText 的左侧部分文本
- python - x 和 y 不能大于 2-D,但具有 (1,) 和 (1, 224, 224, 3) 形状
- json - 如何从json中获取id?
- clearcase - 无法确定路径名的 VOB
- java - 显然 java 在 Linux 和 Windows 上没有相同的 nashorn.jar
- entity-framework - 具有多个 where 子句的 EFCore 查询,它们一起充当 AND 但不是 OR
- python - 配置小部件时出现 Tkinter 类型错误
- scala - gitlab ci:sbt 在每个阶段重新编译
- java - 转储覆盖数据时出错(代码 5013)。Selenium 使用 java Eclipse