刹那的菜鸟

博客园 首页 新随笔 联系 管理

有一个具体的例子 :https://github.com/OrchardCMS/OrchardCore.Samples

1、先使用教程,安装cms -可以是完全 也可以是采用前后端分离管理。
修改对应的program.cs 的内容:
`var builder = WebApplication.CreateBuilder(args);

// Add services to the container.
//builder.Services.AddRazorPages();

builder.Services.AddOrchardCore();
//这是为了 识别其他模块的mvc路径
builder.Services.AddOrchardCore().AddMvc();
// cms
builder.Services.AddOrchardCms().AddMvc();
//builder.Services.AddMvc();
var app = builder.Build();

// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}

app.UseHttpsRedirection();
app.UseStaticFiles();

//原本自带的路由跟授权要注释掉,使用orchardcore的路由跟页面
//app.UseRouting();
//app.UseAuthorization();
//app.MapRazorPages();
//这里是使用orchardcore的
app.UseOrchardCore();
app.Run();
`
对应添加引用





然后要添加的其他net core项目 比如新建一个webapi项目
然后添加引用

其他都不需要变。
再到刚才的cms的项目中 添加webapi的项目引用即可调用它。 可
以在后台管理中开启。或者禁用 类似如下图

这样就可以使用到该项目的路由,通常是需要加该项目的前缀。 这是约定。
也可以在控制器里面 定义 [Route("xxx/[controller]")]
route 的设置会直接忽略项目前缀。 尽量不要跟主cms的路由冲突,比如 admin 就不要设置了。

posted on 2023-10-17 11:15  刹那的菜鸟  阅读(120)  评论(0编辑  收藏  举报