所以我在具有2个get的控制器中有两条路由。当尝试从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}");
但是只能调用索引路由
[Route("/callback")]
应该是
[Route("/Test/callback")]