Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/76.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 缓存中的属性:请求在此上下文中不可用_Jquery_Asp.net_Ajax_Vb.net_Iis - Fatal编程技术网

Jquery 缓存中的属性:请求在此上下文中不可用

Jquery 缓存中的属性:请求在此上下文中不可用,jquery,asp.net,ajax,vb.net,iis,Jquery,Asp.net,Ajax,Vb.net,Iis,我已经看完了所有其他的请求,在这方面是不可用的帖子,所以这种情况似乎是独一无二的 我们应用程序中的许多页面继承自一个基页类,我们称之为BP2,它继承自另一个基页类,我们称之为BP1,它继承自System.Web.UI.page。我们在底层的基本页面BP2中存储了许多共享函数和web方法。我试图从jQuery访问其中一个web方法,但收到错误:请求在此上下文中不可用。从代码隐藏访问该方法效果良好 此web方法是BP2中的公共共享函数,错误似乎来自该函数试图从BP1访问的属性。该属性是存储在Http

我已经看完了所有其他的请求,在这方面是不可用的帖子,所以这种情况似乎是独一无二的

我们应用程序中的许多页面继承自一个基页类,我们称之为BP2,它继承自另一个基页类,我们称之为BP1,它继承自System.Web.UI.page。我们在底层的基本页面BP2中存储了许多共享函数和web方法。我试图从jQuery访问其中一个web方法,但收到错误:请求在此上下文中不可用。从代码隐藏访问该方法效果良好

此web方法是BP2中的公共共享函数,错误似乎来自该函数试图从BP1访问的属性。该属性是存储在HttpContext.Current.Cache中的数据库结果列表,它在第一次请求时填充。但是,查看HttpContext.Current.CurrentHandler对象会发现值为{Request}的属性在此上下文中不可用。}并且它从未填充过。以下是代码的简化版本:

BP2:


编辑:可能需要注意的是,lovDbResult是一个LINQ to SQL结果对象。

显然,我错了这个错误发生的位置。未填充属性,因为在上面psuedo代码中的“从数据库检索并添加到缓存”部分中,有一个对HttpContext.Current.CurrentHandler.Request的调用,该调用在WebMethod调用的上下文中不可用。通过将其更改为HttpContext.Current.Request,已更正此问题

<WebMethod()>
Public Shared Function SaveThing() As Integer
    Return HttpContext.Current.CurrentHandler.GetListOfValueId("something")
End Function
Public ReadOnly Property ListOfValues As List(Of lovDbResult)
    Get
        Return Utility.ListOfValues
    End Get
End Property

Public Function GetListOfValueId(ByVal value As String) As Integer
    If value <> "" Then
        'Problem is in the next line.
        For Each lov In HttpContext.Current.CurrentHandler.ListOfValues.Where(....)
            Return lov.id
        Next
    End If
    Return New Nullable(Of Integer)
End Function
Public Shared ReadOnly Property ListOfValues() As List(Of lovDbResult)
    Get
        If HttpContext.Current.Cache("ListOfValues") Is Nothing Then
            'Retrieve from database and add to cache.
        End If
        Return HttpContext.Current.Cache("ListOfValues")
    End Get
End Property