从ashx重定向到aspx后,会话变量丢失

时间:2018-10-01 15:46:57

标签: asp.net

我有两个asp.net网站项目,例如Website1和Website2。 Website2实际上是Website1下的目录,但它们为开发人员设置为两个不同的网站。

网站1和网站2使用两个不同的数据库(分别是DB1和DB2)。

我需要从DB2的整个表中检索数据,将其发送到Website1,然后将结果显示在Website1中的页面(Results.aspx)上。我这样做的方法是,将ashx文件中的Website2中的数据获取,将其放入Session变量中,然后重定向到Results.aspx。但是在Results.aspx中,Session变量没有任何数据。

我进行了研究,找到了可能的原因,并加以解决,但没有任何改善。相关代码如下:

errorLog.ashx(在Website2中)

<%@ WebHandler Language="VB" Class="errorLog" %>

Imports System.Data

Public Class errorLog : Implements IHttpHandler, IRequiresSessionState

   Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest

        Dim filePath As String = "/admin/Results.aspx" 'file in Website1
        Dim dt As DataTable = ErrorLogData.GetData().Tables(0) 'get data
        context.Session("GAErrorLogs") = dt 'put in Session
        context.Response.Redirect(ServerVariables.GetURL(filePath), False) 'redirect to Website1
    End Sub

    Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
        Get
            Return False
        End Get
    End Property

End Class

Results.aspx(在Website1中)

Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
    Dim dt As DataTable = DirectCast(Session("GAErrorLogs"), DataTable)  'Session is nothing       
End Sub

再次,这不是跨域的,因为Website2在生产中位于Website1下。尽管无法在本地进行测试,但是我正在具有与生产相同目录结构的测试服务器上对其进行测试。

有人可以指出出什么问题了吗?

0 个答案:

没有答案
相关问题