Click here to Skip to main content
15,900,681 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
Hi,

I am Back again with ASP.Net Query this time, ;)

I have Contact us Form with Below Code, When My Server Take Updation , If any one Fill up form its shows error like "No connection could be made because the target machine refuse . . . ( IP address : Port )"

Then My Orignal Problem Starts Here. . . .

(1) My Back End Code Shows (Which written in contact.aspx.vb) which I dont want to SHow,How Can I do this?

(2) My EMail ID and Password shows during this type of errors, How to Put all error in 404 like error Page, so if anything goes wrong on server or updation on process, customers see the error page not the back end code.

Discribed answer , Tutorial or Step-by-Step Guides are most welcome.

Thanks,

My Code :
Imports System.Web.Mail
Imports System.Text

Partial Class _Default
    Inherits System.Web.UI.Page

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        Try
        Dim Body As String = "From:" + fullname.Text + Environment.NewLine + "Mobile:" + mbltxt.Text + Environment.NewLine + "EMail:" + emailtxt.Text + Environment.NewLine + Environment.NewLine + "Message:" + Environment.NewLine + bodytxt.Text
        Dim MM As New System.Net.Mail.SmtpClient
        MM.EnableSsl = False
        MM.Host = "mail.mydomainname.co.in"

        Dim cred As New System.Net.NetworkCredential("help@mydomainname.co.in", "mypassword")
        MM.Credentials = cred
        MM.Send(emailtxt.Text, "help@mydomainname.co.in", subtxt.Text, Body)
        clrfld()
        'MsgBox("Thank You !" + Environment.NewLine + "Your Message has been Sent.", MsgBoxStyle.Information, "EMail Sent")
      Catch ex As Exception         
                'MsgBox("Thank You !" + Environment.NewLine + "Your Message has been Sent.", MsgBoxStyle.Information, "EMail Sent")
     End Try
     End Sub
    Sub clrfld()
        fullname.Text = ""
        mbltxt.Text = ""
        emailtxt.Text = ""
        subtxt.Text = ""
        bodytxt.Text = ""
    End Sub
End Class
Posted
Updated 29-Dec-11 6:27am
v2

1 solution

For your second problem. you can use custom error handling a step further by associating specific errors with specific error pages. The customErrors section can contain error elements that associate particular errors with error pages.
XML
<configuration>
   <system.web>
     <customErrors mode="RemoteOnly" defaultRedirect="apperror.aspx"/>
     <error statusCode="404" redirect="404.aspx" />
  </configuration>
 
Share this answer
 
Comments
s1a2b3 29-Dec-11 23:12pm    
IS THERE ANY WAY TO REDIRECT ALL ERROR TO ONE ERROR PAGE./././?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900