【发布时间】:2011-07-11 13:09:14
【问题描述】:
我正在使用 server.transfer 将 URL 的执行转移到从数据库中获取信息的虚拟页面。问题在于母版页与会话交互。
global.asax:
Sub Application_BeginRequest(ByVal sender As Object, ByVal e As EventArgs)
' Fires at the beginning of each request
If Not (System.IO.File.Exists(Server.MapPath(Request.Url.LocalPath))) And Request.Url.LocalPath.ToLower().EndsWith(".aspx") Then
Server.Transfer("/Utility/utilityCMS.aspx", False)
Else
'error
End If
End Sub
母版页:
If String.IsNullOrEmpty(CStr(Session("SessionId"))) Then
Session.Add("SessionId", Guid.NewGuid().ToString)
End If
页面声明:
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="utilityCMS.aspx.vb" Inherits="utilityCMS" MasterPageFile="~/MasterPages/main.master" EnableSessionState="True" %>
web.config sn-p:
<httpModules>
<add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add name="HttpModuleAggregator" type="XPIdea.Web.HttpModuleAggregator,xpidea.web.common" />
</httpModules>
我收到一个错误:
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 <configuration>\<system.web>\<httpModules> section in the application configuration.
我还应该提到,这个相同的母版页在网站的其他地方也可以使用。 Session 也在整个网站中使用(不仅仅是在母版页中)。
我错过了什么?
【问题讨论】: