我有一個自定義的IValueProvider,我寫處理json值。它在globa.asax中註冊通過MVC3允許HTML和自定義IValueProviders
ValueProviderFactories.Factories.Insert(0, new JsonValueProviderFactory());
它工作正常,但我最近需要發佈一個包含HTML的模型。默認情況下,這產生舊的
A potentially dangerous Request.Form value was detected from the client
錯誤消息。它看起來像通常的解決方法是用AllowHtml屬性來修飾模型屬性。問題是我的價值提供者仍在拋出錯誤。任何想法如何讓我的價值提供者尊重AllowHtml屬性?
下面是相關代碼:
public class JsonValueProvider : IValueProvider, IValueDeserializer
{
private ControllerContext context;
public JsonValueProvider(ControllerContext controllerContext)
{
this.context = controllerContext;
}
public bool ContainsPrefix(string prefix)
{
return context.HttpContext.Request.Form.AllKeys.FirstOrDefault(i => i.StartsWith(prefix)) != null; //<!------- The error is thrown here
}
.....