I have this snippet in my cshtml file:
Expires on: @Model.EndDate.ToString("MMM dd yyyy")
And I get this in the response:
HTTP/1.1 200 OK
Content-Type: text/html
...
Expires on: ׳�׳�׳™ 05 2013
How do I tell Nancy to use UTF8 by default for responses?
Edit: To clarify, this isn't a localization problem, the output is already localized - it's just that the localized UTF8 string is sent to the client without a UTF8 charset declaration, so it gets mucked up in an attempt to treat it as latin1.
What I am looking for is this:
HTTP/1.1 200 OK
Content-Type: text/html; charset=utf-8
...
And I'd like to not have to specify it for each response individually.
I am using the NancyFx web framework
If you want to specify UTF8 charset declaration in your module's response, you can define an After interceptor. Here's how you can define an After Interceptor in your module's constructor:
After += ctx =>
{
...
}
You can also define Application-level hook in your bootstrapper:
pipelines.AfterRequest += (ctx) => { ... };
Update: Based on the comments, best approach would be using the following code in the hook:
if (ctx.Response.ContentType == "text/html")
ctx.Response.ContentType = "text/html; charset=utf-8";
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