2013-02-04 110 views
2

,它可以在這裏找到:http://documentation.mailgun.net/user_manual.html#events-webhooks,尋找「傳遞的事件網絡掛接」MVC4 Mailgun交付網絡掛接

我無法引用Request.Params [」 Message-Id「],除非我修改應用程序的requestValidationMode爲2.0

當我嘗試引用這個字段沒有requestValidationMode = 2.0時,我得到了潛在的不安全錯誤。該字段的內容是:< [email protected]>。我也試圖聲明一個模型來利用自動模型綁定。我的模型如下所示:

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; }   
} 

當我嘗試引用MessageId字段時,它將返回null。我試圖添加

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

由於我對該領域不感興趣, 在Controller中,我給自己定

[ValidateInput(false)] 

我似乎無法得到的消息-ID字段後面。任何幫助?

回答

2

我似乎懂了工作,在任何情況下,運行到同一個問題...

我添加了一個新的模型綁定作爲參考這裏:

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

然後我改變了我模型像這樣:

[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; }   
} 

和所有似乎工作,我並不需要調用

[ValidateInput(false)] 

也在控制器上。

希望幫助別人。