Trying to use Request.ServerVariables("remote_addr")

H

Henry Stock

I don't seem to understand how to use the value:
Request.ServerVariables("remote_addr")

I am trying to pass the ip address of a sending web client in the body of an
email message.

When I compile the following code I get the this error message:

Error 1 'System.Web.HttpRequest.ServerVariables' is a 'property' but is used
like a 'method' D:\Projects\sample\comments.aspx.cs 38 78
D:\Projects\sample\

For all I know, there may be more errors than just haven't shown their head
yet.
Can somebody tell me how to pass the value to my message?

//*****************************************************
protected void contactUS_Click(object sender, EventArgs e)

{

//Things to Do:

// Validate form fields:

// Name field should be letters and spaces only. Can't be blank or only
spaces.

// Phone field may have () - spaces and digits

// email address must be properly formatted.

// Eventually I would like to add a check for domain validity

// After edits I need to create the message

MailMessage msg = new MailMessage();

MailAddress _from = new MailAddress(FindControl("email").ToString());

MailAddress _sender = new MailAddress("(e-mail address removed)");

msg.From = _from;

msg.Sender = _sender;

msg.Subject = "Feedback from Comments Form";

StringBuilder sbuilder = new StringBuilder();

//Build string for message body

sbuilder.AppendLine("Sender's IP Address: " +
Response.Write(Request.ServerVariables("remote_addr")));

sbuilder.AppendLine("Name: " + FindControl("name").ToString());

sbuilder.AppendLine("Phone: " + FindControl("phone").ToString());

sbuilder.AppendLine("Email: " + FindControl("email").ToString());

sbuilder.AppendLine("Message: " + FindControl("message").ToString());

//assign string value to message body

msg.Body = sbuilder.ToString();

//create the smtp client

SmtpClient _smtp = new SmtpClient();

_smtp.DeliveryMethod = SmtpDeliveryMethod.Network;

_smtp.Host = "mrelay.perfora.net";

_smtp.Port = 25;

_smtp.Send(msg);


}

//**************************************************
 
J

Juan T. Llibre

re:
!> I am trying to pass the ip address of a sending web client in the body of an email message

The "sending web client" is your web server in that case.

re:
!> Can somebody tell me how to pass the value to my message?

You'd have to capture the IP when the web client arrives at a preliminary page
which then redirects to your web mail form, passing the IP value to your email form.
 
J

Joe Fawcett

Henry Stock said:
I don't seem to understand how to use the value:
Request.ServerVariables("remote_addr")

I am trying to pass the ip address of a sending web client in the body of
an email message.

When I compile the following code I get the this error message:

Error 1 'System.Web.HttpRequest.ServerVariables' is a 'property' but is
used like a 'method' D:\Projects\sample\comments.aspx.cs 38 78
D:\Projects\sample\

For all I know, there may be more errors than just haven't shown their
head yet.
Can somebody tell me how to pass the value to my message?

//*****************************************************
protected void contactUS_Click(object sender, EventArgs e)

{

//Things to Do:

// Validate form fields:

// Name field should be letters and spaces only. Can't be blank or only
spaces.

// Phone field may have () - spaces and digits

// email address must be properly formatted.

// Eventually I would like to add a check for domain validity

// After edits I need to create the message

MailMessage msg = new MailMessage();

MailAddress _from = new MailAddress(FindControl("email").ToString());

MailAddress _sender = new MailAddress("(e-mail address removed)");

msg.From = _from;

msg.Sender = _sender;

msg.Subject = "Feedback from Comments Form";

StringBuilder sbuilder = new StringBuilder();

//Build string for message body

sbuilder.AppendLine("Sender's IP Address: " +
Response.Write(Request.ServerVariables("remote_addr")));

sbuilder.AppendLine("Name: " + FindControl("name").ToString());

sbuilder.AppendLine("Phone: " + FindControl("phone").ToString());

sbuilder.AppendLine("Email: " + FindControl("email").ToString());

sbuilder.AppendLine("Message: " + FindControl("message").ToString());

//assign string value to message body

msg.Body = sbuilder.ToString();

//create the smtp client

SmtpClient _smtp = new SmtpClient();

_smtp.DeliveryMethod = SmtpDeliveryMethod.Network;

_smtp.Host = "mrelay.perfora.net";

_smtp.Port = 25;

_smtp.Send(msg);


}

//**************************************************
In C# you need [] rather than ():
Request.ServerVariables["remote_addr"]
 

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

Similar Threads

System.Security.SecurityException: Request 5
emailsender 0
Trying to send an email 1
SmtpClient Email Error 1
Email problem 3
Send Email Timeout... 2
Mail message attachement problem 1
Problem on sending emails 1

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,015
Latest member
AmbrosePal

Latest Threads

Top