0

我正在使用 AttributeRouting 并遵循 AttributeRouting.NET 中的本地化示例并添加了一个文化处理程序:

routes.MapAttributeRoutes(config => {
  config.ConstrainTranslatedRoutesByCurrentUICulture = true;
  config.CurrentUICultureResolver = (httpContext, routeData) => {
    return (string)routeData.Values["culture"] ?? Thread.CurrentThread.CurrentUICulture.Name;
  };
  config.UseRouteHandler(() => new CultureRouteHandler());
});

我在 CultureRouteHandler 和解析器中添加了断点。

当我启动站点时,没有任何断点被触发......

所以我无法为第一个请求选择默认文化。

我的 CultureRouteHandler 如下:

protected override IHttpHandler GetHttpHandler(RequestContext context) {

  String culture = (String)context.RouteData.Values[_culture];

  if (culture == null) {
    culture = "en";
  }

  if (culture != null) {
    Thread.CurrentThread.CurrentCulture = new CultureInfo(culture);
    Thread.CurrentThread.CurrentUICulture = new CultureInfo(culture);
    context.RouteData.Values[_culture] = culture;
  }

  return base.GetHttpHandler(context);

} // GetHttpHandler  

如何解决?

谢谢你,米格尔

4

0 回答 0