server.transfer会话问题asp.net

时间:2011-03-09 01:03:03

标签: asp.net vb.net .net-3.5

我正在使用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片段:

<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.

我还应该提到这个相同的母版页在网站的其他地方工作。会话也在整个站点中使用(不仅仅在母版页中)。

我错过了什么?

2 个答案:

答案 0 :(得分:0)

在母版页页面指令中启用会话状态。

答案 1 :(得分:0)

如果您正在进行例行安全检查,我建议您使用所有安全页面都可以继承并在那里进行检查的基页,而不是在每次请求时将请求弹回多个页面。我可以想象所有开销都会受到性能影响。我看到了很多类似于你的问题,但没有具体的答案。