0

I need to create a web api that accepts a multipart form request that contains input for text, file fields. Now I'm facing a problem that I cannot send html text through the text field.

[HttpPost]
public HttpResponseMessage SampleController()
{
    try
    {
        var httpRequest = HttpContext.Current.Request;
        var sendItem = httpRequest.Params["Body"];
    }
}

The code above shows the api controller. It accepts a 'Body' field that contains Html contents. When parsing the request by controller caught an Error shown below.

System.Web.HttpRequestValidationException: 'A potentially dangerous Request.Form value was detected from the client (Body="<p><b>Hai</b></p>").

Web.config:

<system.web>
  <compilation debug="true" targetFramework="4.7.2" />
  <httpRuntime targetFramework="4.7.2" />
</system.web>

How to solve this issue so that it can accept text with html?

GSerg
  • 76,472
  • 17
  • 159
  • 346
  • You need to encode the html entities before sending them. – jgetner Apr 26 '20 at 06:56
  • @jgetner https://stackoverflow.com/questions/81991/a-potentially-dangerous-request-form-value-was-detected-from-the-client#comment4192833_81991 – GSerg Apr 26 '20 at 06:57

0 Answers0