的OutputCache没有让改变网站的语言 [英] OutputCache not let to change site language

查看:137
本文介绍了的OutputCache没有让改变网站的语言的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用的OutputCache快速打开网页​​。

I want to use OutputCache to open pages quickly.

我控制器写道:

public class HomeController : Controller
{
[OutputCache(Duration=3600,VaryByParam="none", VaryByCustom="lang")]
public ActionResult Index()
{
   //........
 }

public ActionResult ChangeCulture( string lang, string returnUrl )
{
  Session["Culture"] = new CultureInfo( lang );
  return Redirect( returnUrl );
}
}

在Layout.cshtml:

In Layout.cshtml:

<a href="@Url.Action( "ChangeCulture", "Home", new { lang = "en", returnUrl = this.Request.RawUrl } )">Eng</a>
<a href="@Url.Action( "ChangeCulture", "Home", new { lang = "az", returnUrl = this.Request.RawUrl } )">Az</a>

在Global.asax中:

In Global.asax:

protected void Application_AcquireRequestState( object sender, EventArgs e )
{
//It's important to check whether session object is ready
if ( HttpContext.Current.Session != null )
{
CultureInfo ci = ( CultureInfo )this.Session["Culture"];

//Checking first if there is no value in session and set default language this can happen for first user's request
if ( ci == null )
{
//Sets default culture to english invariant
string langName = "az";

//Try to get values from Accept lang HTTP header
if ( HttpContext.Current.Request.UserLanguages != null &&
HttpContext.Current.Request.UserLanguages.Length != 0 )
{
//Gets accepted list 
langName = HttpContext.Current.Request.UserLanguages[0].Substring( 0, 2 );
}
ci = new CultureInfo( langName );
this.Session["Culture"] = ci;
}
//Finally setting culture for each request
Thread.CurrentThread.CurrentUICulture = ci;
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture( ci.Name );
}
}

public override string GetVaryByCustomString( HttpContext context, string value )
{
if ( value.ToLower() == "lang" )
{
return Thread.CurrentThread.CurrentUICulture.Name;
}
return base.GetVaryByCustomString( context, value );
}

但我不能改变网站的语言。比如,我切换语言为英文,它改变了,但后来想回到阿塞拜疆语,它没有改变。什么是我的错? (对不起,我英文不好)

But I cannot change site language. For example, I switch language to English, It changes, but then want to return Azerbaijan language, it did not changes. What is my mistake? (Sorry for bad English)

推荐答案

我解决了自己,改变了

<globalization culture="en" uiCulture="en" />

 <globalization culture="auto" uiCulture="auto" />

在配置文件中。然后它的工作。

in config file. Then it worked.

这篇关于的OutputCache没有让改变网站的语言的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆