【问题标题】:server.transfer session issue asp.netserver.transfer 会话问题 asp.net
【发布时间】: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 也在整个网站中使用(不仅仅是在母版页中)。

我错过了什么?

【问题讨论】:

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


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

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

      【讨论】:

      • 对不起,这也没有运气。
      猜你喜欢
      • 2010-11-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多