By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,203 Members | 1,549 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,203 IT Pros & Developers. It's quick & easy.

Trying to use Request.ServerVariables("remote_addr")

P: n/a
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("in**@morristwpgop.org");

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_add r")));

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);
}

//**************************************************
Aug 16 '08 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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.

Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
"Henry Stock" <he***@henry-stock.comwrote in message news:eT**************@TK2MSFTNGP06.phx.gbl...
>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("in**@morristwpgop.org");

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_add r")));

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);
}

//**************************************************


Aug 16 '08 #2

P: n/a


"Henry Stock" <he***@henry-stock.comwrote in message
news:eT**************@TK2MSFTNGP06.phx.gbl...
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("in**@morristwpgop.org");

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_add r")));

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"]

--

Joe Fawcett (MVP - XML)
http://joe.fawcett.name

Aug 16 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.