Question

I'm having an issue making use of the Mailgun delivered webhook, it can be found here: http://documentation.mailgun.net/user_manual.html#events-webhooks, look for "Delivered Event Webhook"

I am unable to reference Request.Params["Message-Id"] unless I modify the app's requestValidationMode to 2.0

I do get the potentially unsafe error when trying to reference this field without requestValidationMode = 2.0. The contents of the field are: <20130203200110.12345.12345@mydomain.mailgun.org>. I've also tried to declare a model to take advantage of auto model binding. My model looks like this:

public class MailgunDeliveredEvent
{
    public string Id { get; set; }
    public string Event { get; set; }
    public string Recipient { get; set; }
    public string Domain { get; set; }

    [AllowHtml]
    [JsonProperty(PropertyName="Message-Id")]
    public object MessageId { get; set; }

    public int Timestamp { get; set; }
    public string Token { get; set; }
    public string Signature { get; set; }        
}

When I attempt to reference the MessageId field it returns null. I've tried to add

[Bind(Exclude="message-headers")]

As I'm not interested in that field. In the Controller, I've set

[ValidateInput(false)]

I can't seem to get the Message-Id field back. Any help?

Was it helpful?

Solution

I seem to have got it working, in case anyone runs into the same issue...

I added a new model binder as referenced here:

Asp.Net MVC 2 - Bind a model's property to a different named value

I then changed my model like so:

[ModelBinder(typeof(DefaultModelBinderEx))]
public class MailgunDeliveredEvent
{
    public string Id { get; set; }
    public string Event { get; set; }
    public string Recipient { get; set; }
    public string Domain { get; set; }

    [BindAlias("Message-Id")]
    public string MessageId { get; set; }

    public int Timestamp { get; set; }
    public string Token { get; set; }
    public string Signature { get; set; }        
}

And all seems to work, I didn't need to call

[ValidateInput(false)]

on the controller either.

Hope that helps someone.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top