0

The Twilio documentation provides a guide for asp.net MVC, but not for webforms. I am able to send an SMS message with no problem, but receiving SMS replies is where I am stuck. I have found that it is recommended for webforms users, to use a generic handler, but that is all I have so far, and I do not know how to get the information from the handler. And also, I have to give a URL to the Twilio console and I do not know what URL to give. I can put it on any of my website pages, example "mywebsite.com/??" "??" is I don't know where and how to reference my handler.

I have created the handler "message.ashx" here:

Public Class message : Implements IHttpHandler

Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
    Context.Response.ContentType = "application/xml"
    Dim Body = Context.Request.Forms("Body")
    Dim response As New Twilio.TwiML.MessagingResponse()
    response.Message("You said: " & Body)
    Context.Response.Write(response.ToString())
 End Sub

Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
    Get
        Return False
    End Get
End Property

End Class

So the question is, now that I have this handler in place, how do I get the information on an aspx page to view? And what url do I give to Twilio console for the reply. I am using C# but the answer can be in C# or VB.NET, as I can get translated.

mlg74
  • 520
  • 1
  • 7
  • 27
  • 2
    If you're familiar with Web Forms, it's probably easiest to add a generic handler (.ashx) to your app. You should see that in Visual Studio's Add New Item menu. Then wherever the .ashx file is at, is where the URL will be. So if your .ashx is at /somefolder/myhandler.ashx, then the URL will be yoursite.com/somefolder/myhandler.ashx. As for getting the information onto an ASPX page, you'd probably save it somewhere (such as a database) and then on the other page you'd read it from there. – mason Sep 15 '21 at 23:24
  • 1
    You know you can add ASP.NET MVC to an existing ASP.NET site, even if that site already has Web Forms in it. That might be easier, and it gives you a path to upgrade the rest of your site (as Web Forms is pretty much a dead platform). – mason Sep 15 '21 at 23:26

1 Answers1

0

I was able to solve this with the help from comments above. This is Httphandler in aspx webforms. The problem was that they updated their references so having the correct word helped, such as "MessagingResponse", vs. "Twilio.TwiML.MessagingResponse". I also tried migrate my site to MVC, and got it to work with Twilio, but had other issues with the migration. Now I just need to figure out how to actually receive the text that was sent from a user. The Twilio documentation is pretty vague on a lot of things.

Public Class SmsHandler : Implements IHttpHandler

Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
    context.Response.ContentType = "application/xml"        
    Dim response = New MessagingResponse
    response.Message("Hello World?")        
    context.Response.Write(response.ToString())
End Sub

Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
Get
    Return False
End Get
End Property

 End Class
mlg74
  • 520
  • 1
  • 7
  • 27