6

有没有办法通过来自客户端的传入请求设置从 SS 返回的错误消息的文化?我可以以某种方式设置 JSONService 客户端的文化,然后让 SS 以该文化响应消息文本。

4

1 回答 1

3

是的,您可以在预请求过滤器中设置每个请求的当前文化:

host.PreRequestFilters.Add((httpReq, httpResp) =>
{
    Thread.CurrentThread.CurrentUICulture = DefaultCulture;

    if (httpReq.Headers.AllKeys.Contains(HttpHeaderKeys.AcceptLanguage))
    {
        var cinfo = new CultureInfo(httpReq.Headers[HttpHeaderKeys.AcceptLanguage]);
        if (new ResourceManager(typeof(ResourceFile)).GetResourceSet(cinfo, false, false) != null)
            Thread.CurrentThread.CurrentUICulture = cinfo;
    }
});
于 2013-12-10T15:50:06.657 回答