The remote server returned an error: (404) Not Found

The remote server returned an error: (404) Not Found

Post by Shakee » Tue, 27 Sep 2005 20:54:39


Hi All,

I am facing an Exception "The remote server returned an error: (404) Not
Found" in a web-application in which I am trying to maile through SMTP. The
description of the Application is as under:

I have developed a template to generate HTML of mail's body
(emailform.aspx). I get its "HttpWebRequest" object and then Stream object
by using "getRequestStream" method of HttpWebRequest object to send data.
After sending data when I try to get "HttpWebResponse" object, I receive
"The remote server returned an error: (404) Not Found" exception. I tried to
search out it on Internet, I found that it is the problem of security and
have to add "aspnet" user to the virtual directory. I've done this, but
still My problem is unsoled. The code of the page in which I try to get
object of "emailform.aspx" page is available as under. This is written in
code window of another page (not in emailform.aspx).

Try
Dim strURL As String

Dim strPostData As New StringBuilder

'get Absolute URL of the emailform.aspz page.

strURL = ConfigurationSettings.AppSettings("emailform")



For Each var As String In Request.Form

If var <> "__VIEWSTATE" Then

strPostData.Append(var)

strPostData.Append("=")

strPostData.Append(Request.Form(var))

strPostData.Append("&")

End If

Next



Dim encoding As New ASCIIEncoding

Dim byte1 As Byte() = encoding.GetBytes(strPostData.ToString())



Dim objWebRequest As HttpWebRequest =
CType(System.Net.HttpWebRequest.Create(strURL), HttpWebRequest)

objWebRequest.Method = "POST"

' Set the content type of the data being posted.

objWebRequest.ContentType = "application/x-www-form-urlencoded"

' Set the content length of the string being posted.

objWebRequest.ContentLength = strPostData.Length

Dim newStream As Stream = objWebRequest.GetRequestStream()

newStream.Write(byte1, 0, byte1.Length)

newStream.Close()

'HERE THERE COME EXCEPTION WHEN I TRY TO GET HTTPWEBRESONSE OBJECT

Dim objWebResponse As HttpWebResponse = CType(objWebRequest.GetResponse,
HttpWebResponse)

Dim objSR As StreamReader = New
StreamReader(objWebResponse.GetResponseStream())



Dim msg As New MailMessage

msg.Subject = "Wedding Proposal Form"

msg.BodyFormat = MailFormat.Html

msg.Body = objSR.ReadToEnd()

msg.From = ConfigurationSettings.AppSettings("FROM")

msg.To = ConfigurationSettings.AppSettings("TO")

SmtpMail.SmtpServer = ConfigurationSettings.AppSettings("SERVER")

SmtpMail.Send(msg)

objWebRequest = Nothing

objWebResponse = Nothing

objSR = Nothing

newStream = Nothing

Server.Transfer("thanks.aspx?code=200")

Catch ex As Exception

'Response.Write(ex.ToString())

End Try



Note: I am very thankful for one who will provide me the solution. and this
virtual directory is at root of wwwRoot directory.

Thanks.