'RedirectToAction passes to end of current action and goes nowhere
Here is the controller route that is being hit successfully:
[Route("begin")]
public ActionResult BeginSmsMessaging(SmsRequest message)
{
string from = message.From;
var phoneNumber = from.Replace("+1", "").FormatPhoneNumber();
_commandPipeline.Publish(new LogInboundMessage
{
PhoneNumber = phoneNumber,
TimestampUtc = DateTime.UtcNow
});
int code;
if(int.TryParse(message.Body, out code))
{
try
{
return RedirectToAction("DiaryQuestions");
}
catch(Exception e)
{
string error = e.Message;
return null;
}
}
else
{
return RedirectToAction("UnknownCode");
}
}
Neither the RedirectToAction("DiaryQuestions") nor the RedirectToAction("UnknownCode") are successfully redirecting. Instead, execution moves to the end of the current BeginSmsMessaging action and then slips into IoC code where the controller is released and program execution just stops.
Here is the unreachable DiaryQuestions action:
[Route("diaryQuestions")]
public ActionResult DiaryQuestions(SmsRequest message)
{
var response = new TwilioResponse();
response.SetAttributeValue("PhoneNumber", message.From);
response.SetAttributeValue("DiaryQuestion", "1");
response.Message("This is a test message.");
response.Sms("This is a test SMS");
return TwiML(response);
}
And the unreachable UnknownCode action:
[Route("unknownCode")]
public ActionResult UnknownCode(SmsRequest message)
{
var response = new TwilioResponse();
response.Sms("What to say...");
return TwiML(response);
}
No errors are thrown in either the console or Windows Event Viewer. Also, everything looks good up until the RedirectToAction call - input parameters and variables are all populated correctly.
I have no idea at this point what could be happening. :(
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
