httpcontext - Access issue RRS feed

  • Question

  • User-1738841732 posted

    How do I resolve this

    I get this error on HttpContext, when I try to get the server Name

    httpcontext is not declared it may be inaccessible due to its protection level

    Dim strServerName As String = If((HttpContext.Current IsNot Nothing), HttpContext.Current.Request.ServerVariables("LOCAL_ADDR").ToString(), Environment.MachineName)

    Thursday, March 28, 2019 1:17 PM


  • User753101303 posted


    Which message you have if using the full name ie System.Web.HttpContext.Current ? Uou may need Imports System.Web to bing the correct namespace in scope. See https://docs.microsoft.com/en-us/dotnet/visual-basic/programming-guide/program-structure/namespaces

    BTW I believe your approach won't work. A common catch is to try code that seems to work because your machine is both the web server and on the browser side. On a real web server it would give the name of the web server and I think you rather try to get the IP / machine name of the client machine ?

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, March 28, 2019 1:33 PM