Thursday, March 29, 2012

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

What is the equivalent for retrieving server side variables?
For example in PHP, one such predefined variable is: $_SERVER['REMOTE_ADDR']"Frank Moyles" <fgmoyles@.nospam.com> wrote in message
news:ceKdne8KddpqoenaRVnyjwA@.bt.com...
> 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 Rae
ASP.NET MVP
http://www.markrae.net
"Gran Andersson" <guffa@.guffa.com> wrote in message
news:uIV97CVSIHA.4584@.TK2MSFTNGP03.phx.gbl...

> 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.
Mark Rae
ASP.NET MVP
http://www.markrae.net

0 comments:

Post a Comment