Saturday, November 13, 2004

Server Variables and .NET

The server variables collection can be very helpful when you are developing applications in .NET. The proper syntax to refer to a server variable in your code is Request.ServerVariables("VariableName") such as to:( Don't forget to declare variable such as; Dim IP as String and then:)
  • Retrieves the user IP Address

IP = Request.ServerVariables ("REMOTE_ADDR")

  • Retrieves the remote host IP Address
dnsIP = Request.ServerVariables("remote_host")
  • Retrieves the page domain name

serverName = Request.ServerVariables("server_name")

  • Retrieves the referer url
referer = request.servervariables("http_referer")
  • Gets the browser type
agent = Request.ServerVariables("http_user_agent")

  • Retrieves page url
Url=request.servervariables("URL")

  • Retrieves request mehtod .. get or post
method=request.servervariables("Request_Method")

  • Retrieves server port
serverPort=request.servervariables("server_port")

  • Retrieves current page
scriptName=request.servervariables("script_name")

  • Retrieves server software
serverSoftware=request.servervariables("server_software")

Consult the Microsoft Documentation for a full description of all the Server Variables.This handy list is a for commonly used server variables including referred above:
  • ALL_HTTP
  • AUTH_TYPE
  • CONTENT_LENGTH
  • CONTENT_TYPE
  • GATEWAY_INTERFACE
  • HTTP_ACCEPT
  • HTTP_ACCEPT_LANGUAGE
  • HTTP_CONNECTION
  • HTTP_USER_AGENT
  • HTTP_COOKIE
  • HTTP_HOST
  • HTTP_COOKIE
  • HTTP_REFERER
  • LOGON_ACCEPT_ENCODING
  • PATH_INFO
  • PATH_TRANSLATED
  • QUERY_STRING
  • REMOTE_ADDR
  • REMOTE_IDENT
  • REMOTE_HOST
  • REQUEST_METHOD
  • SCRIPT_MAP
  • SCRIPT_NAME
  • SERVER_NAME
  • SERVER_PORT
  • SERVER_PORT_SECURE
  • SERVER_PROTOCOL
  • SERVER_SOFTWARE
  • URL

No comments: