無法使用會話當我嘗試使用一個會話veriable在InitializeCulture,我得到了如下因素的錯誤:在InitializeCulture
Session state can only be used when enableSessionState is set to true, either in a configuration file or in the Page directive. Please also make sure that System.Web.SessionStateModule or a custom session state module is included in the \\ section in the application configuration.
這就是引發錯誤的代碼
public class BasePage : Page
{
public string Lang { get; set; }
protected override void InitializeCulture()
{
if (!Page.IsPostBack)
{
if (!string.IsNullOrEmpty(Request.QueryString["lang"]))
{
Session["lang"] = Request.QueryString["lang"].ToLower();
}
if (Session["lang"] != null && !string.IsNullOrEmpty((string)Session["lang"]))
{
Lang = (string)Session["lang"];
string selectedCulture = Lang == "nl" ? "nl-BE" : "fr-BE";
UICulture = selectedCulture;
Culture = selectedCulture;
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(selectedCulture);
Thread.CurrentThread.CurrentUICulture = new CultureInfo(selectedCulture);
}
base.InitializeCulture();
}
}
}
我改變了我的Web.Config,就像在錯誤中獲得的一樣。但它一直在拋出同樣的錯誤。
<pages enableSessionState="true">
<controls>
<add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add tagPrefix="asp" namespace="System.Web.UI.WebControls" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</controls>
</pages>
<httpModules>
<remove name="Session" />
<add name="Session" type="System.Web.SessionStateModule" />
<add type="Intelligencia.UrlRewriter.RewriterHttpModule, Intelligencia.UrlRewriter" name="UrlRewriter"/>
<add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</httpModules>
有沒有人有解決方案?謝謝!!!
感謝您的回覆。不幸的是,這是行不通的。 – Vinzcent
您是否檢查過ASP.NET狀態服務是否正在運行? – rla4
此外,如果您在Windows 2008上使用IIS7,則您的模塊應位於部分中,而不是 - http://stackoverflow.com/questions/2757403/error-using-session-in- iis-7 –
rla4