Re: Trying to use Request.ServerVariables("remote_addr")

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance





"Henry Stock" <henry@xxxxxxxxxxxxxxx> wrote in message news:eTxwn22$IHA.4816@xxxxxxxxxxxxxxxxxxxxxxx
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("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);


}

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


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

--

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

.



Relevant Pages

  • Trying to use Request.ServerVariables("remote_addr")
    ... I am trying to pass the ip address of a sending web client in the body of an ... protected void contactUS_Click(object sender, EventArgs e) ... //assign string value to message body ... //create the smtp client ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Trying to use Request.ServerVariables("remote_addr")
    ... 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. ... //assign string value to message body ... //create the smtp client ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: CAN You help Re: Writing dictionary output to a file
    ... import string, StringIO ... for w in msg: ... I have a piece of code, which does check for matching ... word in the email message by comparing with the words ...
    (comp.lang.python)
  • Email Cmd
    ... I have a Command that generates an email message as follows: ... Dim strMessage As String 'Body of message ... Dim strSubject As String 'Email Subject ...
    (microsoft.public.access.formscoding)
  • Re: Using scalar instead of stream
    ... > there is a way to use a scalar instead? ... There is no string here ... to which you have loaded an email message. ... Are you *ever* going to bother reading the Posting Guidelines for this ...
    (comp.lang.perl.misc)