尝试在ASP.NET-MVC中通过Twilio创建可用的VoIP电话失败,因为网站上只有XML而不是电话可见

尝试在ASP.NET-MVC中通过Twilio创建可用的VoIP电话失败,因为网站上只有XML而不是电话可见,asp.net-mvc,twilio,voip,asp.net-mvc-5.2,Asp.net Mvc,Twilio,Voip,Asp.net Mvc 5.2,我一直在ASP.NET-MVC中搜索VoIP技术。我唯一找到的就是Twilio 我创建了ASP.NET-MVC 5.2应用程序,并添加了对以下内容的引用: Twilio.Api Twilio.Mvc Twiml 我将\u Layout.csthml降至最低: <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <meta name="viewport" conten

我一直在ASP.NET-MVC中搜索VoIP技术。我唯一找到的就是Twilio

我创建了ASP.NET-MVC 5.2应用程序,并添加了对以下内容的引用:

  • Twilio.Api
  • Twilio.Mvc
  • Twiml
我将
\u Layout.csthml
降至最低:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
    @Styles.Render("~/Content/css")
    @Scripts.Render("~/bundles/modernizr")
</head>
<body>
        @RenderBody()
</body>
</html>
我已经从下载了how-to的内容并将其粘贴到:PhoneMenu.csthml,然后将其添加到我的项目中的
视图/Home/

@{

    @*@start snippet*@
    @* Define Menu *@
    Dictionary<string, string[]> web = new Dictionary<string, string[]>() {
        {"default",new string[] {"receptionist","hours", "location", "duck"} },
        {"location",new string[] {"receptionist","east-bay", "san-jose", "marin"} }
    };

    Uri cleanedUri = new Uri(Request.Url.GetComponents(UriComponents.AbsoluteUri & ~UriComponents.Port, UriFormat.UriEscaped));
    string baseUri = cleanedUri.AbsoluteUri.Remove(cleanedUri.AbsoluteUri.Length - cleanedUri.Segments.Last().Length);

    @* Get the menu node, index, and url *@
    string node = Request["node"] != null ? Request["node"] : "";
    int index = Request["Digits"] != null ? int.Parse(Request["Digits"]) : 0;

    string url = string.Format("{0}phonemenu.cshtml", baseUri);

    @* Check to make sure index is valid *@
    string destination = string.Empty;
    if (web.Keys.Contains(node) && web[node].Length >= index && Request["Digits"] != null) {
        destination = web[node][index];
    } else {
        destination = string.Empty;
    }
    @*end snippet*@

    @*start snippet*@
    @* Render TwiML *@
    Response.ContentType = "text/xml";
    var twiml = new Twilio.TwiML.TwilioResponse();

    switch (destination) {
        case "hours":
            twiml.Say("Initech is open Monday through Friday, 9am to 5pm");
            twiml.Say("Saturday, 10am to 3pm and closed on Sundays");
            break;
        case "location":
            twiml.Say("Initech is located at 101 4th St in San Francisco California");
            twiml.BeginGather(new { action = "phonemenu.cshtml?node=location", numDigits = "1" })
                .Say("For directions from the East Bay, press 1")
                .Say("For directions from San Jose, press 2");
            twiml.EndGather();
            break;
        case "east-bay":
            twiml.Say("Take BART towards San Francisco / Milbrae. Get off on Powell Street. Walk a block down 4th street");
            break;
        case "san-jose":
            twiml.Say("Take Cal Train to the Milbrae BART station. Take any Bart train to Powell Street");
            break;
        case "duck":
            twiml.Play("duck.mp3");
            break;
        case "receptionist":
            twiml.Say("Please wait while we connect you");
            twiml.Dial("NNNNNNNNNN");
            break;
        default:
            twiml.BeginGather(new { action = "phonemenu.cshtml?node=default", numDigits = "1" })
                .Say("Hello and welcome to the Initech Phone Menu")
                .Say("For business hours, press 1")
                .Say("For directions, press 2")
                .Say("To hear a duck quack, press 3")
                .Say("To speak to a receptionist, press 0");
            twiml.EndGather();
            break;
    }
    @*end snippet*@

    @*start snippet*@
    if (destination != String.Empty && destination != "receptionist") {
        twiml.Pause();
        twiml.Say("Main Menu");
        twiml.Redirect(url);
    }
    @*end snippet*@
}
@Html.Raw(twiml.ToString())
可见结果:


问题:如何生成可用的手机?由于我找不到任何来源如何实现,如果有比Twilio更简单的替代方案,那就太好了。

Twilio TwiML一代不需要进入Razor视图,而只需使用控制器即可。因此,您可能会有如下内容:

public ActionResult PhoneMenu() {
    var response = new TwimlResponse().Say("Hello"):
    return new TwimlResult(response);
}
或者,作为Twilio.Mvc的一部分,您可以选择从TwilioController继承一个替代控制器,这样您就可以执行以下操作:

public class PhoneMenuController : TwilioController
{
    public ActionResult PhoneMenu()
    {
        var response = new TwimlResponse().Say("Hello");
        return Twiml(response);
    }
}

完整的文档可以在GitHub上找到,网址是

,一开始我不理解。你能看看我的问题吗?
public ActionResult PhoneMenu() {
    var response = new TwimlResponse().Say("Hello"):
    return new TwimlResult(response);
}
public class PhoneMenuController : TwilioController
{
    public ActionResult PhoneMenu()
    {
        var response = new TwimlResponse().Say("Hello");
        return Twiml(response);
    }
}