0

我在调用以下函数时收到“在此上下文错误中不可用的响应”:

Private Sub ReloadPage(ByVal inNumber As Integer) Handles tempaux.Advertise
    'Response.Redirect("tope.aspx?dep=" & CStr(inNumber))
    Response.Write("<script>window.open('tope.aspx?dep= & CStr(inNumber)','topFrame');</script>")
End Sub

我已经更改了在 Response.Write 之前添加 System.Web.HttpContext.Current 的行,我得到“对象引用未设置为对象的实例”。

提供一些背景知识:如您所见,tope.aspx 是在 topframe 中打开的。一旦加载它就会启动我定义的 CustomTimer 对象:

Public Class tope
    Inherits System.Web.UI.Page
    Public funciones As funciones = New funciones
    Dim WithEvents tempaux As CustomTimer = Global.objCustomTimer

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim inUserProfile As Int64
        Try
            tempaux.StartTimer()
        Catch ex As Exception
            'bla bla
        End Try

如您所见,我已经在 Global.asax 中声明了 CustomTimer。CustomTimer 对象每 5 秒引发一次 Advertise 事件,并将“inNumber”作为参数传递给 tope.aspx 页面以刷新一些标签,这是一件简单的事情。CustomTimer 是我为管理计时器而创建的一个类,它不继承任何其他类(对于我在搜索中学到的内容,它必须继承一些 httpthing 但我不确定)。我猜想在某些时候 httpcontext 正在丢失(我在谷歌中搜索过,我无法弄清楚它的生命周期或任何告诉我为什么它“死掉”的信息)。谁能帮我找出问题所在?

谢谢

4

1 回答 1

0

您的计时器存在于顶部页面类之外,因此可能在页面响应完成并且不再存在 HttpContext.Current 实例后触发计时器事件。

听起来您正在尝试做的是在页面加载后每 5 秒更改一次页面上的广告横幅。您需要使用 javascript 计时器来执行此操作,该计时器每 5 秒触发一次,并向您的 Web 服务器发出请求以获取新广告。

于 2012-05-31T16:41:18.207 回答