my ASP.NET MVC Application is UTF-8, but I receive POST request in Encoding.Default from third-party app out of my control.
What is sanest and simplest way to change request encoding for only one action of one controller? (Rest of my application should remain UTF-8).
public class Message
{
public int id { get; set; }
public string phone { get; set; }
public string mes { get; set; }
public string to { get; set; }
}
[HttpPost]
public ActionResult Receive(Message msg)
{
AddIncomingMessage(msg);
return new EmptyResult();
}
You can do Action based request encoding in ASP.NET MVC with web.config location tag setting.
Sample web.config:
<configuration>
...
<location path="path/to/your/actionmethod">
<system.web>
<globalization requestEncoding="ISO-8859-1" responseEncoding="ISO-8859-1" />
</system.web>
</location>
...
</configuration>
http://www.siimviikman.com/2012/06/12/action-based-request-encoding-in-asp-net-mvc/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With