In this guide, we'll cover how to set up your ASP.NET development environment for an MVC project. We'll also talk about a couple of helpful tools that we recommend for all C# applications that use Twilio: ngrok and the Twilio C# SDK.
Let's get started!
This tutorial is intended for Visual Studio on Windows with .NET Framework. For a cross-platform tutorial using .NET Core, please check out our Programmable SMS Quickstart for C# with .NET Core.
For Windows, we recommend using Visual Studio Community Edition, which is a free IDE provided by Microsoft. It will install all the necessary components as well as the .NET Framework. You can also follow along with this tutorial using Visual Studio Professional or Enterprise.
First, let's create a simple ASP.NET MVC project. Visual Studio can create everything for you in a few simple clicks.
_16using System.Web.Mvc;_16using Twilio.AspNet.Mvc;_16using Twilio.TwiML;_16_16namespace WebApplicationTwilio.Controllers_16{_16 public class HomeController : TwilioController_16 {_16 public ActionResult Index()_16 {_16 var response = new VoiceResponse();_16 response.Say("hello world");_16 return TwiML(response);_16 }_16 }_16}
And that's it. You can press F5 and you should see a page displaying
_10<Response>_10 <Say>hello world</Say>_10</Response>
Now that you have a simple "Hello World!" in TwiML, your development environment is ready to go. But for most Twilio projects you'll want to install one more helpful tool: ngrok.
Most Twilio services use webhooks to communicate with your application. When Twilio receives an incoming phone call, for example, it reaches out to a URL in your application for instructions on how to handle the call.
When you're working on your application in your development environment, your app is only reachable by other programs on the same computer, so Twilio won't be able to talk to it.
ngrok is our favorite tool for solving this problem. Once started, it provides a unique URL on the ngrok.io domain which will forward incoming requests to your local development environment.
To start, head over to the ngrok download page and grab the binary for your operating system. (For more details on installing ngrok, read our ngrok guide.)
Once downloaded, run your ASP.NET MVC application and take note of the URL in the browser to find the port number your application is running on: