Find client IP, client name, browser, referrer from ASP.NET

N

NWx

Hi,

I have a ASP.NET application using forms authentication
Default page is default.aspx, and login page is login.aspx

As I perform authentication in Login page, I want to update a log table with
both successful and unsuccessful logins.

As usual, client computer connects first to default.aspx, but since it isn't
authenticated, it is redirected to login.aspx.

1. How can I get client IP address, and client browser type?
2. How can I perform reverse DNS lookup to find client DNS name?
3. I'd like to register also referrer address. But since in Login page
referrer is always default.aspx, what can I do to be able to pass the
referrer from default.aspx to login.aspx (in any variable, cache, context,
whatsoever)? Since actually no code is executed in default.aspx, to be able
to set any variable, but instead aspnet process redirect client
automatically to login.aspx.

Thank you.
 
D

Darrin J Olson

You can capture that information by writing your code in the Session_Start
event in the Global.asax file. Use an instance of the System.Web.HttpRequest
class to get the values you mention below.

-Darrin
 
J

John Saunders

NWx said:
Hi,

I have a ASP.NET application using forms authentication
Default page is default.aspx, and login page is login.aspx

As I perform authentication in Login page, I want to update a log table with
both successful and unsuccessful logins.

As usual, client computer connects first to default.aspx, but since it isn't
authenticated, it is redirected to login.aspx.

1. How can I get client IP address, and client browser type?

You can use Request.UserHostAddress, but it will probably just be the
address of their firewall or NAT box.
2. How can I perform reverse DNS lookup to find client DNS name?

Request.UserHostName will get you the name if it's available and if it's not
the name of their firewall or NAT box.
3. I'd like to register also referrer address. But since in Login page
referrer is always default.aspx, what can I do to be able to pass the
referrer from default.aspx to login.aspx (in any variable, cache, context,
whatsoever)? Since actually no code is executed in default.aspx, to be able
to set any variable, but instead aspnet process redirect client
automatically to login.aspx.

You can't do this. You never get to default.aspx if the user is not
authenticated, so default.aspx can't pass anything to login.aspx.

The referrer isn't always available, either. Request.UrlReferrer may be
null.
 

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

Forum statistics

Threads
473,990
Messages
2,570,211
Members
46,796
Latest member
SteveBreed

Latest Threads

Top