简体   繁体   中英

How to receive incoming sms in twilio using c# webforms?

I am using Twilio API to send and receive SMS in c#. I have implemented send SMS successfully. The problem is in receiving SMS. Twilio documentation only shows MVC code to receive SMS. Is it possible to receive SMS in asp.net web forms? Here is the documentation to receive SMS. Receive SMS in twilio

My project is in asp.net web form. Do I need to switch to the MVC?

Twilio evangelist here.

If you're using WebForms, I generally recommend receiving SMS messages using a Generic HTTP Handler. Twilio passes parameters like the message body as form encoded params, so its easy to grab those from the request context.

public class Twiml : IHttpHandler
{
    public void ProcessRequest(HttpContext context)
    {
        context.Response.ContentType = "application/xml";

        var Body = context.Request.Forms["Body"];

        var response = new Twilio.TwiML.MessageResponse();
        response.Message("You said: " + Body);

        context.Response.Write(response.ToString());
    }

    public bool IsReusable
    {
        get
        {
            return false;
        }
    }
}

Hope that helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM