Re: Trying to use Request.ServerVariables("remote_addr")
- From: "Joe Fawcett" <joefawcett@xxxxxxxxxxxxxxxx>
- Date: Sat, 16 Aug 2008 14:52:59 +0100
"Henry Stock" <henry@xxxxxxxxxxxxxxx> wrote in message news:eTxwn22$IHA.4816@xxxxxxxxxxxxxxxxxxxxxxx
I don't seem to understand how to use the value:In C# you need [] rather than ():
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("info@xxxxxxxxxxxxxxxx");
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);
}
//**************************************************
Request.ServerVariables["remote_addr"]
--
Joe Fawcett (MVP - XML)
http://joe.fawcett.name
.
- References:
- Trying to use Request.ServerVariables("remote_addr")
- From: Henry Stock
- Trying to use Request.ServerVariables("remote_addr")
- Prev by Date: Re: Miscellaneous ASP.NET question on a mail form...
- Next by Date: Re: Miscellaneous ASP.NET question on a mail form...
- Previous by thread: Re: Trying to use Request.ServerVariables("remote_addr")
- Next by thread: DataList & Paging
- Index(es):
Relevant Pages
|