Asp.net 在自定义事件中丢失HttpContext

Asp.net 在自定义事件中丢失HttpContext,asp.net,Asp.net,调用以下函数时,我收到“响应在此上下文错误中不可用”: 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)',

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

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
如您所见,我已经在Global.asax中声明了CustomTimer。CustomTimer对象每5秒引发一次播发事件,并将“inNumber”作为参数传递给tope.aspx页面以刷新某个标签,这很简单。CustomTimer是我为管理计时器而创建的一个类,它不继承任何其他类(就我在搜索中了解到的内容而言,它必须继承一些httpthing,但我不确定)。我猜在某个时候httpcontext正在丢失(我在google中搜索过,无法计算它的生命周期或任何告诉我它为什么会死的信息)。有人能帮我找出问题所在吗


谢谢

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


听起来你要做的是在页面加载后,每5秒更改一次页面上的广告横幅。您需要使用javascript计时器来完成这项工作,该计时器每5秒启动一次,并向您的web服务器请求新广告。

Hmmm我明白了。问题是“刷新”的时间是从数据库中获取的,它甚至可以在运行时更改,而且我必须重新加载页面,给它一个参数也是从数据库获取的。我的想法是用VB管理一切。当你点击一个按钮然后使用Respose.Redirect时,难道没有一种方法可以像应用程序那样“创建一个HttpContext”吗?我想另一个选择是使用AJAX,但由于我使用的是Visual Studio 2003,我不知道它是否得到很好的支持。您可以尝试创建HttpContext,但响应不会返回到用户的浏览器,因为它没有启动请求。根据你问题中的描述,我相信javascript是刷新广告所需要的。如果不是,你需要提供更多的描述。
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