Sending SMS from ASP.NET Web Application Using Twilio API

Donald Symmons 3,066 Reputation points
2025-05-12T11:39:39.1333333+00:00

I am attempting to implement a feature that allows a user to send an SMS to a mobile number from a web application using the Twilio API.

The application setup consists of two text boxes:

DestnationPhone.Text

SmsMessage.Text

In this feature, a user will enter the mobile phone number in the DestnationPhone text box and the message in the SmsMessage text box. After this, the user will click the send button to send the message to the recipient's mobile number.

I would like guidance on how to achieve this using the Twilio API. Below is the code I have attempted, but I am encountering errors on two lines, and I am unsure if it is correct.

Please see the code snippet in the image below for reference:

Twilio Image code

Can someone provide assistance on how to properly implement this feature?

Developer technologies C#
{count} votes

2 answers

Sort by: Most helpful
  1. Bruce (SqlWork.com) 77,686 Reputation points Volunteer Moderator
    2025-05-12T15:28:13.76+00:00

    The Twilio examples used named parameters, which your code doesn’t, so probably you have them in the wrong order.


  2. P a u l 10,761 Reputation points
    2025-05-12T18:29:44.4133333+00:00

    Like Bruce said you need to specify the names of the parameters for MessageResource.Create calls as there are a lot of parameters accepted by this call & they're not in the same order as your example, i.e.:

    https://github.com/twilio/twilio-csharp/blob/dc59b77d18b18a7525aee78743879e4f01e6dbe6/src/Twilio/Rest/Api/V2010/Account/MessageResource.cs#L216

    Here's an example (note the to:, from: body: and client: before each value, making it unambiguous):

    // Now that we have our custom built TwilioRestClient,
    // we can pass it to any REST API resource action.
    var message = MessageResource.Create(
        to: new PhoneNumber("+15017122661"),
        from: new PhoneNumber("+15017122661"),
        body: "Hey there!",
        // Here's where you inject the custom client
        client: twilioRestClient
    );
    

    Lifted this example from here: https://github.com/twilio/twilio-csharp/blob/HEAD/advanced-examples/custom-http-client.md


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.