Twilio 如何将重定向附加到ASP.NET Core 2.1中的VoiceResponse?

Twilio 如何将重定向附加到ASP.NET Core 2.1中的VoiceResponse?,twilio,Twilio,使用Twilio5.16 Asp.Net核心2.1.1 我有一个代码示例,我正试图从asp.net mvc移植到asp.netcore 我在确定线路的用途时遇到问题: response.Redirect(Url.ActionUri("ShortWelcome", "IVR")); 因为Url上不再有“ActionUri”方法 我的控制器操作: using Twilio.AspNet.Core; using Twilio.TwiML; using Twilio.TwiML.Voice; nam

使用Twilio5.16 Asp.Net核心2.1.1

我有一个代码示例,我正试图从asp.net mvc移植到asp.netcore 我在确定线路的用途时遇到问题:

response.Redirect(Url.ActionUri("ShortWelcome", "IVR"));
因为Url上不再有“ActionUri”方法

我的控制器操作:

using Twilio.AspNet.Core;
using Twilio.TwiML;
using Twilio.TwiML.Voice;

namespace IVRPhoneTree.Core.Web.Controllers
{
    public abstract class ControllerBase : TwilioController
    {
        public TwiMLResult RedirectWelcome()
        {
            var response = new VoiceResponse();
            response.Say("Returning to the main menu ", Say.VoiceEnum.PollyBrian, 1, Say.LanguageEnum.EnAu);
            response.Redirect(Url.ActionUri("Welcome", "IVR"));

            return TwiML(response);
        }



        public TwiMLResult RedirectBadPin()
        {
            var response = new VoiceResponse();
            response.Say("Sorry that pin is not correct. Returning you to the main menu. ",
                Say.VoiceEnum.PollyBrian, 1, Say.LanguageEnum.EnAu);
            response.Redirect(Url.ActionUri("ShortWelcome", "IVR"));

            return TwiML(response);
        }


    }
}

TIA

我最终使用了aspnet内核内置DI

因此,在启动配置服务中:

services
            .AddSingleton<IActionContextAccessor, ActionContextAccessor>()
            .AddScoped<IUrlHelper>(x => x
                .GetRequiredService<IUrlHelperFactory>()
                .GetUrlHelper(x.GetRequiredService<IActionContextAccessor>().ActionContext));
这使我能够:

 public TwiMLResult RedirectBadPin()
    {
        var response = new VoiceResponse();
        response.Say("Sorry that pin is not correct. Returning you to the main menu. ",
            Say.VoiceEnum.PollyBrian, 1, Say.LanguageEnum.EnAu);

        string path = _urlHelper.Action("ShortWelcome", "IVR");

        response.Redirect(new Uri(path, UriKind.Absolute), HttpMethod.Get);   

        return TwiML(response);
    }

它是否类似于:response.Redirect(newURI(“../IVR/ShortWelcome”)、HttpMethod.Get?我遇到了类似的问题,您的解决方案引发System.UriFormatException:“无效URI:无法确定URI的格式。”
 public TwiMLResult RedirectBadPin()
    {
        var response = new VoiceResponse();
        response.Say("Sorry that pin is not correct. Returning you to the main menu. ",
            Say.VoiceEnum.PollyBrian, 1, Say.LanguageEnum.EnAu);

        string path = _urlHelper.Action("ShortWelcome", "IVR");

        response.Redirect(new Uri(path, UriKind.Absolute), HttpMethod.Get);   

        return TwiML(response);
    }