How to check if browser is running on the web server?

D

Dr. StrangeDub

I am part of a group that has developed an ASP.Net web application. I
am looking for a way to determine whether or not the browser is
actually running on the web server. For this case (when executing IE
on the webserver) I want to remove a link to Remote Desktop -- as the
desktop is NOT remote in this case, and I believe doesn't work
attempting remote access to one's self. I wrote the following code to
check the "browser on server" condition and it works fine, as long as
I have a DNS server:
public static bool CheckBrowserOnServer()
{
bool foundIPmatchFlag = false; // Assume no match
string userhost= HttpContext.Current.Request.UserHostAddress;
string serverhost = Dns.GetHostName(); // get name of server
IPHostEntry ipserverhost = Dns.GetHostByName(serverhost);
IPAddress[] addresses = ipserverhost.AddressList; // get list
// Look for an IP address match
foreach ( IPAddress address in addresses )
{
if (userhost == address.ToString())
{
foundIPmatchFlag = true; // got a match
break;
}
}
return foundIPmatchFlag;

Would anyone know how to accomplish the same thing in an environment
WITHOUT DNS? Ideally I'd like to have my test be server-side, but I'd
certainly consider client-side logic (i.e. Javascript) that could
achieve the same ends.

Thanks in advance,
Michael Rose
Unisys Corp
 
W

William Ryan eMVP

Hi Michael

If I understand you correctly, I think you can just use the Process class
and check for iexplore.exe and if it's running, either kill it or do what
you want. You can check for other browsers too if you need it finely
grained

Dr. StrangeDub said:
I am part of a group that has developed an ASP.Net web application. I
am looking for a way to determine whether or not the browser is
actually running on the web server. For this case (when executing IE
on the webserver) I want to remove a link to Remote Desktop -- as the
desktop is NOT remote in this case, and I believe doesn't work
attempting remote access to one's self. I wrote the following code to
check the "browser on server" condition and it works fine, as long as
I have a DNS server:
public static bool CheckBrowserOnServer()
{
bool foundIPmatchFlag = false; // Assume no match
string userhost= HttpContext.Current.Request.UserHostAddress;
string serverhost = Dns.GetHostName(); // get name of server
IPHostEntry ipserverhost = Dns.GetHostByName(serverhost);
IPAddress[] addresses = ipserverhost.AddressList; // get list
// Look for an IP address match
foreach ( IPAddress address in addresses )
{
if (userhost == address.ToString())
{
foundIPmatchFlag = true; // got a match
break;
}
}
return foundIPmatchFlag;

Would anyone know how to accomplish the same thing in an environment
WITHOUT DNS? Ideally I'd like to have my test be server-side, but I'd
certainly consider client-side logic (i.e. Javascript) that could
achieve the same ends.

Thanks in advance,
Michael Rose
Unisys Corp

--
W.G. Ryan MVP Windows - Embedded

http://forums.devbuzz.com
http://www.knowdotnet.com/dataaccess.html
http://www.msmvps.com/williamryan/
 
D

Dr. StrangeDub

Thanks for the input, but I think you misread my question -- or I
phrased it badly. I don't want to know if these is an IExplore.exe
processing running on the web server machine, I want to know if I
(i.e., the browser accessing the ASP.Net app) am remote or not? That
is, where is the browser running the app from - a remote client or
right on the machine hosting the website?

-Michael Rose

Hi Michael

If I understand you correctly, I think you can just use the Process class
and check for iexplore.exe and if it's running, either kill it or do what
you want. You can check for other browsers too if you need it finely
grained

Dr. StrangeDub said:
I am part of a group that has developed an ASP.Net web application. I
am looking for a way to determine whether or not the browser is
actually running on the web server. For this case (when executing IE
on the webserver) I want to remove a link to Remote Desktop -- as the
desktop is NOT remote in this case, and I believe doesn't work
attempting remote access to one's self. I wrote the following code to
check the "browser on server" condition and it works fine, as long as
I have a DNS server:
public static bool CheckBrowserOnServer()
{
bool foundIPmatchFlag = false; // Assume no match
string userhost= HttpContext.Current.Request.UserHostAddress;
string serverhost = Dns.GetHostName(); // get name of server
IPHostEntry ipserverhost = Dns.GetHostByName(serverhost);
IPAddress[] addresses = ipserverhost.AddressList; // get list
// Look for an IP address match
foreach ( IPAddress address in addresses )
{
if (userhost == address.ToString())
{
foundIPmatchFlag = true; // got a match
break;
}
}
return foundIPmatchFlag;

Would anyone know how to accomplish the same thing in an environment
WITHOUT DNS? Ideally I'd like to have my test be server-side, but I'd
certainly consider client-side logic (i.e. Javascript) that could
achieve the same ends.

Thanks in advance,
Michael Rose
Unisys Corp
 
N

Nick Malik

Note: local access uses IP address 127.0.0.1 and/or the name "localhost" in
the URL.

In addition, if the user doesn't have DNS, then they are either using WINS
to resolve the address or they are typing IP addresses. The latter is
fairly unlikely.
With WINS, the name in the URL will match the machine name for the web
server.

So, look for the machine name, localhost, or the local IP address
(127.0.0.1) and you should cover the bases fairly well.

--- Nick

Dr. StrangeDub said:
Thanks for the input, but I think you misread my question -- or I
phrased it badly. I don't want to know if these is an IExplore.exe
processing running on the web server machine, I want to know if I
(i.e., the browser accessing the ASP.Net app) am remote or not? That
is, where is the browser running the app from - a remote client or
right on the machine hosting the website?

-Michael Rose

Hi Michael

If I understand you correctly, I think you can just use the Process class
and check for iexplore.exe and if it's running, either kill it or do what
you want. You can check for other browsers too if you need it finely
grained

Dr. StrangeDub said:
I am part of a group that has developed an ASP.Net web application. I
am looking for a way to determine whether or not the browser is
actually running on the web server. For this case (when executing IE
on the webserver) I want to remove a link to Remote Desktop -- as the
desktop is NOT remote in this case, and I believe doesn't work
attempting remote access to one's self. I wrote the following code to
check the "browser on server" condition and it works fine, as long as
I have a DNS server:
public static bool CheckBrowserOnServer()
{
bool foundIPmatchFlag = false; // Assume no match
string userhost= HttpContext.Current.Request.UserHostAddress;
string serverhost = Dns.GetHostName(); // get name of server
IPHostEntry ipserverhost = Dns.GetHostByName(serverhost);
IPAddress[] addresses = ipserverhost.AddressList; // get list
// Look for an IP address match
foreach ( IPAddress address in addresses )
{
if (userhost == address.ToString())
{
foundIPmatchFlag = true; // got a match
break;
}
}
return foundIPmatchFlag;

Would anyone know how to accomplish the same thing in an environment
WITHOUT DNS? Ideally I'd like to have my test be server-side, but I'd
certainly consider client-side logic (i.e. Javascript) that could
achieve the same ends.

Thanks in advance,
Michael Rose
Unisys Corp
 
D

Dr. StrangeDub

Thanks Nick (and others) for your input.

I think the localhost part of Nick's answer matches what we ended up
doing.

-Michael Rose
Unisys Corp

Note: local access uses IP address 127.0.0.1 and/or the name "localhost" in
the URL.

In addition, if the user doesn't have DNS, then they are either using WINS
to resolve the address or they are typing IP addresses. The latter is
fairly unlikely.
With WINS, the name in the URL will match the machine name for the web
server.

So, look for the machine name, localhost, or the local IP address
(127.0.0.1) and you should cover the bases fairly well.

--- Nick

Dr. StrangeDub said:
Thanks for the input, but I think you misread my question -- or I
phrased it badly. I don't want to know if these is an IExplore.exe
processing running on the web server machine, I want to know if I
(i.e., the browser accessing the ASP.Net app) am remote or not? That
is, where is the browser running the app from - a remote client or
right on the machine hosting the website?

-Michael Rose

Hi Michael

If I understand you correctly, I think you can just use the Process class
and check for iexplore.exe and if it's running, either kill it or do what
you want. You can check for other browsers too if you need it finely
grained

I am part of a group that has developed an ASP.Net web application. I
am looking for a way to determine whether or not the browser is
actually running on the web server. For this case (when executing IE
on the webserver) I want to remove a link to Remote Desktop -- as the
desktop is NOT remote in this case, and I believe doesn't work
attempting remote access to one's self. I wrote the following code to
check the "browser on server" condition and it works fine, as long as
I have a DNS server:
public static bool CheckBrowserOnServer()
{
bool foundIPmatchFlag = false; // Assume no match
string userhost= HttpContext.Current.Request.UserHostAddress;
string serverhost = Dns.GetHostName(); // get name of server
IPHostEntry ipserverhost = Dns.GetHostByName(serverhost);
IPAddress[] addresses = ipserverhost.AddressList; // get list
// Look for an IP address match
foreach ( IPAddress address in addresses )
{
if (userhost == address.ToString())
{
foundIPmatchFlag = true; // got a match
break;
}
}
return foundIPmatchFlag;

Would anyone know how to accomplish the same thing in an environment
WITHOUT DNS? Ideally I'd like to have my test be server-side, but I'd
certainly consider client-side logic (i.e. Javascript) that could
achieve the same ends.

Thanks in advance,
Michael Rose
Unisys Corp
 

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

Top