所以我在一个控制器中有两条路线,有 2 条路线。当试图从 Razor 调用它时,只调用第一个。我不确定是否需要在启动或属性中添加一些内容。
[ApiController]
[Route("[controller]")]
public class TestController : BaseController
{
[HttpGet]
public async Task<IActionResult> Index()
{
return Content("1");
}
[Route("/callback")]
[HttpGet("[controller]/[action]")]
public async Task<IActionResult> Callback(string state, string code)
{
return Content("2");
}
}
在我的启动中,我配置了以下端点
app.UseEndpoints(endpoints =>
{
endpoints.MapRazorPages();
endpoints.MapControllers();
endpoints.MapFallbackToFile("index.html");
});
然后我在我的剃刀文件代码部分使用一些脚本来调用控制器
var httpClient = new HttpClient();
httpClient.BaseAddress = new Uri(Navigation.BaseUri);
var response = await httpClient.GetAsync($"Test/callback?code={Code}&state={State}");
但是只能调用 Index 路由