Note that there are some explanatory texts on larger screens.

plurals
  1. POData validation ASP MVC OnActionExecuting
    primarykey
    data
    text
    <p>I have created a base controller that each of my controllers inherit. In this controller I have the OnActionExecuting method. I use this to check the url for some parameters. The problem I have is that I get an exception whenever I post html data. I have setup the model using the [AllowHTML] tag and it works on all the other actions. </p> <p>How do I make the OnActionExecuting method pay attention to the model validation?</p> <p>This is what I have in my base controller</p> <pre><code>public abstract class BaseController : Controller { [ValidateInput(false)] protected override void OnActionExecuting(ActionExecutingContext filterContext) { if ((Request.Params["api"] == null || string.IsNullOrEmpty(Request.Params["api"]))) return; if ((Request.Params["api"] != null &amp;&amp; !string.IsNullOrEmpty(Request.Params["api"]))) { if (Session["api"] == null) { Session["api"] = Request.Params["api"]; } } } </code></pre> <p>and below is an extract from my model</p> <pre><code>[MetadataType(typeof (MessagingMetaData))] public partial class Message { } public class MessagingMetaData { [Required] [Display(Name = "Message")] [DataType(DataType.Html)] [AllowHtml] public string Body { get; set; } } </code></pre> <p>here is the stack trace</p> <pre><code>[System.Web.HttpRequestValidationException] Exception Message: A potentially dangerous Request.Form value was detected from the client (Content=" sdafdsafdsafdsac__DisplayClass12.b__d(String value, String key) at Microsoft.Web.Infrastructure.DynamicValidationHelper.LazilyEvaluatedNameObjectEntry.ValidateObject() at Microsoft.Web.Infrastructure.DynamicValidationHelper.LazilyEvaluatedNameObjectEntry.GetValidatedObject() at Microsoft.Web.Infrastructure.DynamicValidationHelper.LazilyValidatingArrayList.get_Item(Int32 index) at System.Collections.Specialized.NameObjectCollectionBase.BaseGetKey(Int32 index) at System.Collections.Specialized.NameValueCollection.GetKey(Int32 index) at System.Collections.Specialized.NameValueCollection.Add(NameValueCollection c) at System.Web.HttpRequest.FillInParamsCollection() at System.Web.HttpRequest.GetParams() at System.Web.HttpRequest.get_Params() at System.Web.HttpRequestWrapper.get_Params() at ProjectX.BaseController.OnActionExecuting(ActionExecutingContext filterContext) at System.Web.Mvc.Controller.System.Web.Mvc.IActionFilter.OnActionExecuting(ActionExecutingContext filterContext) at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) at System.Web.Mvc.ControllerActionInvoker.&lt;&gt;c__DisplayClass15.&lt;&gt;c__DisplayClass17.b__14() at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor, IDictionary`2 parameters) at System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) at System.Web.Mvc.Controller.ExecuteCore() at System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) at System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) at System.Web.Mvc.MvcHandler.&lt;&gt;c__DisplayClass6.&lt;&gt;c__DisplayClassb.b__5() at System.Web.Mvc.Async.AsyncResultWrapper.&lt;&gt;c__DisplayClass1.b__0() at System.Web.Mvc.Async.AsyncResultWrapper.&lt;&gt;c__DisplayClass8`1.b__7(IAsyncResult _) at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`1.End() at System.Web.Mvc.Async.AsyncResultWrapper.End[TResult](IAsyncResult asyncResult, Object tag) at System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) at System.Web.Mvc.MvcHandler.&lt;&gt;c__DisplayClasse.b__d() at System.Web.Mvc.SecurityUtil.b__0(Action f) at System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Action action) at System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) at System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean&amp; completedSynchronously) </code></pre> <p>sorry for the layout would not copy new lines for some reason</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload