Server side variables (e.g. $_SERVER['REMOTE_ADDR']) - dotNet equivalent?

  • Thread starter Thread starter Frank Moyles
  • Start date Start date
F

Frank Moyles

What is the equivalent for retrieving server side variables?

For example in PHP, one such predefined variable is: $_SERVER['REMOTE_ADDR']
 
Frank Moyles said:
What is the equivalent for retrieving server side variables?

For example in PHP, one such predefined variable is:
$_SERVER['REMOTE_ADDR']


string strRemoteAddr = Request.ServerVariables["REMOTE_ADDR"].ToString();
 
Mark said:
Frank Moyles said:
What is the equivalent for retrieving server side variables?

For example in PHP, one such predefined variable is:
$_SERVER['REMOTE_ADDR']


string strRemoteAddr = Request.ServerVariables["REMOTE_ADDR"].ToString();

The ServerVariables collection is a collection of strings, so just do:

string strRemoteAddr = Request.ServerVariables["REMOTE_ADDR"];

Besides, the collection returns null if there is no item by the
specified name, and calling ToString on a null reference causes an
exception.
 
The ServerVariables collection is a collection of strings, so just do:

string strRemoteAddr = Request.ServerVariables["REMOTE_ADDR"];

Besides, the collection returns null if there is no item by the specified
name, and calling ToString on a null reference causes an exception.

You're quite correct - I should have been more specific.
 
Back
Top