HttpContext.Current - это Ничто (так же, как null в C #) в веб-сервисе asmx - PullRequest
0 голосов
/ 31 мая 2019
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.ComponentModel

<System.Web.Services.WebService(Namespace:="http://tempuri.org/")> _
<System.Web.Services.WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<ToolboxItem(False)> _

Public Class Starter
    Inherits System.Web.Services.WebService

    <WebMethod()>
    Public Shared Sub Invoke()
        Dim webForm = New WebForm1()
        ScriptManager.RegisterStartupScript(webForm, GetType(Page), "Execute", "document.getElementById('confirm').click;", True)
        HttpContext.Current.Response.Redirect("Dashboard.aspx") 'System.NullReferenceException

        MsgBox(HttpContext.Current IsNot Nothing) 'False
    End Sub

End Class

Я уже погуглил по другим вопросам (здесь или на других сайтах).Многие упоминали о EnableSession = True.Я пробовал это в своем коде, но после этого было показано сообщение об ошибке:

'EnableSession' не объявлен.Он может быть недоступен из-за уровня защиты.

Как я могу исправить HttpContext.Current?Нужно ли добавлять какие-либо параметры конфигурации в web.config для веб-службы asmx?Спасибо

...