Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8399093
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T21:12:27+00:00 2026-06-09T21:12:27+00:00

mvc – First get result for request.params get exception, second get is ok. i

  • 0

mvc – First “get” result for request.params get exception, second “get” is ok.
i have a page that has a field with xml text in it.
i am using validation=false.
but, on post method in the controller i am trying to get the requset.params and i get an error of
“A potentially dangerous Request.Form value was detected from the client”. after some digging and debugging i see that first time i am trying to get the request.params i get an exception, BUT when i try to get it for the second time everything is ok.

this is the filter i am using to avoid problems with the xml (i am converting it to binary data and empty the xml string field):

   public class RestAPIAttribute : ActionFilterAttribute
    {
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
                 ((SimulationModel)filterContext.ActionParameters["model"]).Data = CommonConverters.StringToByteArray(((SimulationModel)filterContext.ActionParameters["model"]).StringData);
            ((SimulationModel)filterContext.ActionParameters["model"]).StringData = string.Empty;


            base.OnActionExecuting(filterContext);
        }
    }

and this is the post method:

   [HttpPost]
    [ValidateInput(false)]
    [RestAPIAttribute]
    public ActionResult EditSimulation(Guid id, SimulationModel model)
    {
        try
        {
            model.RelationModel = new RelationModel(false, this.Resource("Simulations.AddToObjects"), "SimulationToObjects", id, sessionId, Request.Params, new List<ObjectTypes>() { ObjectTypes.Entity, ObjectTypes.EntityType, ObjectTypes.Universe });
        }
        catch (Exception ex)
        {
            Logger.LogException(ex);
        }

        /* more code here*/

        return View(newModel);
    }

now, as you can see one of the RelationModel’s constuctor has a parameter of request.param which is giving me the problem.

my currenty workaround for this issue is just calling it twice (but i am looking for better solution or at least an explanation):

   [HttpPost]
    [ValidateInput(false)]
    [RestAPIAttribute]
    public ActionResult EditSimulation(Guid id, SimulationModel model)
    {
        try
        {
             try
            {
                model.RelationModel = new RelationModel(false, this.Resource("Simulations.AddToObjects"), "SimulationToObjects", id, sessionId, Request.Params, new List<ObjectTypes>() { ObjectTypes.Entity, ObjectTypes.EntityType, ObjectTypes.Universe });
            }
            catch
            {
                model.RelationModel = new RelationModel(false, this.Resource("Simulations.AddToObjects"), "SimulationToObjects", id, sessionId, Request.Params, new List<ObjectTypes>() { ObjectTypes.Entity, ObjectTypes.EntityType, ObjectTypes.Universe });
            }
        }
        catch (Exception ex)
        {
            Logger.LogException(ex);
        }

        /* more code here*/

        return View(newModel);
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T21:12:28+00:00Added an answer on June 9, 2026 at 9:12 pm

    If this is ASP.NET MVC 3+ you could use the [AllowHtml] attribute on your model property that contains the XML. This will disable request validation only for this property and not the entire request:

    public class SimulationModel 
    { 
        [AllowHtml]
        public string StringData { get; set; } 
    }
    

    and then:

    [HttpPost]
    public ActionResult EditSimulation(Guid id, SimulationModel model)
    {
        // you could directly use model.StringData here without any 
        // encoding needed
    
        return View(newModel);
    }
    

    And if this is an ASP.NET MVC 2 application running in ASP.NET 4.0 in addition to decorating your controller action with the [ValidateInput(false)] attribute you might need to put the following in your web.config:

    <httpRuntime requestValidationMode="2.0"/>
    

    If it is an ASP.NET MVC 3 application you don’t need to put this line in your web.config in order to use the [ValidateInput(false)] attribute.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does MVC 3 support Xml data? I have a model class with a field
MVC 3 VB.NET razor. I have a view that has 4 dropdown boxes in
MVC 3 RTM. Have a model that has an attribute with AllowHtml. In my
MVC newbie question re binders. Supposing I have two strongly typed partial actions that
My MVC application has a simple file download controller action that downloads a file.
MVC @Html.TextBoxFor(model => model.SomeNotNullableType) When using this helper, if I have a type that
MVC website- On the home page header section, I have a drop down with
mvc - c# - aspx => i have a DDL(drop down list), that shows
MVC 3, VB.NET. I have a form in my app that gets basic information
aspnet mvc has the HandleError filter that will return a view if an error

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.