Первое, что я сделал, это изменил Startup.cs, чтобы настроить базовую / интуитивно понятную маршрутизацию.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseHttpsRedirection();
app.UseRouting();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
name: "default",
pattern: "api/{controller=Voice}/{action=Index}/{id?}");
});
}
Затем снова в VoiceController новый Uri () больше не выдает ошибок:
[HttpPost]
public IActionResult Index()
{
var response = new VoiceResponse();
var gather = new Gather(numDigits: 1, action: new Uri("/api/voice/gather", UriKind.Relative));
gather.Say("To do one thing, press 1. To do another thing, press 0.", voice: "Polly.Nicole");
response.Append(gather);
// If the user doesn't enter input, loop
response.Redirect(new Uri("/api/voice", UriKind.Relative));
return TwiML(response);
}