You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I created a Cms.Web project, and would like to add API controllers in the same project, however, when I call builder.Services.AddControllers() in program.cs, the pages don't render properly.
public class Program
{
public static void Main(string[] args)
{
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllers();
builder.Services.AddOrchardCms();
var app = builder.Build();
app.UseRouting();
app.UseStaticFiles();
app.UseOrchardCore();
app.MapControllers();
app.Run();
}
}
my controller
[Route("api/[controller]")]
[ApiController]
[AllowAnonymous]
public class DemoController : ControllerBase
{
[HttpGet]
public IActionResult GetValue([FromQuery]string id)
{
return Ok(new { id });
}
}
I've also tried creating the api controller as shown in the demo and queries module in a separate module project, but i can't hit it at Cms.Module.Api/api/test/value or at /api/test/value
namespace Cms.Module.Api.Controllers
{
[Route("api/test")]
[ApiController]
[AllowAnonymous, IgnoreAntiforgeryToken]
public class TestController : ControllerBase
{
[HttpGet]
public IActionResult Value()
{
return Ok(new { id = 1 });
}
}
}
ahhh never mind I forgot to provide the route names for the actions.
since I didn't provide route names, both methods can be accessed via: api/test or api/demo
if I would like to hit it via api/test/value, I need to add the [HttpGet("value")] to the controller method
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I created a Cms.Web project, and would like to add API controllers in the same project, however, when I call
builder.Services.AddControllers()
in program.cs, the pages don't render properly.my controller
I've also tried creating the api controller as shown in the demo and queries module in a separate module project, but i can't hit it at
Cms.Module.Api/api/test/value
or at/api/test/value
ahhh never mind I forgot to provide the route names for the actions.
since I didn't provide route names, both methods can be accessed via:
api/test
orapi/demo
if I would like to hit it via
api/test/value
, I need to add the[HttpGet("value")]
to the controller methodBeta Was this translation helpful? Give feedback.
All reactions