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

F

Frank Moyles

What is the equivalent for retrieving server side variables?

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

Mark Rae [MVP]

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();
 
G

Göran Andersson

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.
 
M

Mark Rae [MVP]

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top