This is my first time creating a from in ASP.NET I am following a tutorial here
This is the error:
Line 23: output += "<p>Groupe: " + Request.Form["c_Groupe"].ToString() + ".</p>";
Line 24: output += "<p>Numéro de téléphone: " + Request.Form["c_Tel"].ToString() + ".</p>";
Line 25: output += "<p>J'aimerais être bénévole pour: " + Request.Form["La bibliothèque","Aide en classe","Aide pour les dîners pizza","Aide aux devoirs après l’école","Aménagement paysager (fleurs, arbustes à tailler…)","Photo scolaire","Accompagner les élèves lors des sorties", "Venir parler de votre métier dans une classe ou monter un atelier "].ToString() + ".</p>";
Line 26: output += "<p>Autres: " + Request.Form["c_Autr开发者_如何转开发e"].ToString() + ".</p>";
Line 27:
Put
<configuration>
<system.web>
<customErrors mode="Off"/>
</system.web>
</configuration>
In your web.config so we can see the error but It's probably something to do with the
CodeFile="contact-form.aspx.cs" Inherits="_Emailer"
Bit. Either the contact-form.aspx.cs file is missing or the partial class in the code-behind has a different name to _Emailer.
Ah, It looks like you have created a web application project. You need to either build the project first and then ftp all the files to your web server including the bin folder or an easier alternative is to use Visual Studios publish option which will prompt you for your ftp details and do the rest for you
are you coding this for asp.net 1.1 or asp.net 2.0?
The syntax looks like it is for asp.net 2.0 but your web server is running in 1.1 mode.
for asp.net 1.1 the following line:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="contact-form.aspx.cs" Inherits="_Emailer" %>
should be:
<%@ Language="C#" Inherits="_Emailer" src="contact-form.aspx.cs" %>
If you have access to the web sever, just switch the .net Framework version to v2.0 and you should be good to go without having to make any modifications. If not let me know.
I rewrote your codebehind for asp.net 1.1.... I'm doing this from memory so there might be mistakes..
using System;
using System.Text;
using System.Web.Mail;
public class _Emailer : System.Web.UI.Page
{
protected void Page_Load(object sender, System.EventArgs e)
{
if(IsPostBack)
{
try
{
string output = "";
MailMessage mail = new MailMessage();
string hostAddress = "aaa.bbb.ccc.ddd";
string message = Request.Form["c_Message"].ToString();
message = message.Replace(Environment.NewLine, "<br />");
StringBuilder sb = new StringBuilder();
sb.AppendFormat("<p>Nom du Parent: {0}.</p>", Request.Form["c_Name"].ToString());
sb.AppendFormat("<p>Nom de votre enfant: {0}.</p>", Request.Form["c_Enfant"].ToString());
sb.AppendFormat("<p>Groupe: {0}.</p>", Request.Form["c_Groupe"].ToString());
sb.AppendFormat("<p>Numéro de téléphone: {0}.</p>", Request.Form["c_Tel"].ToString());
sb.AppendFormat("<p>J'aimerais être bénévole pour: {0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}.</p>",
Request.Form["La bibliothèque"].ToString(),
Request.Form["Aide en classe"].ToString(),
Request.Form["Aide pour les dîners pizza"].ToString(),
Request.Form["Aide aux devoirs après l’école"].ToString(),
Request.Form["Aménagement paysager (fleurs, arbustes à tailler…)"].ToString(),
Request.Form["Photo scolaire"].ToString(),
Request.Form["Accompagner les élèves lors des sorties"].ToString(),
Request.Form["Venir parler de votre métier dans une classe ou monter un atelier"].ToString()
);
sb.AppendFormat("<p>Autres: {0}.</p>", Request.Form["c_Autre"].ToString());
mail.Subject = "New e-mail.";
mail.From = "marcfavreau@cdsm.qc.ca";
mail.To = "toaddress@domain.com";
mail.Body = sb.ToString();
mail.BodyFormat = MailFormat.Html
SmtpMail.SmtpServer = hostAddress;
SmtpMail.Send(mail);
lblOutCome.Text = "E-mail sent successfully.";
}
catch (Exception err)
{
lblOutCome.Text = "There was an exception whilst sending the e-mail: " + err.ToString() + ".";
}
}
}
}
update your web.config file to show errors
<customErrors mode="Off" />
Removing your header probably isn't the best solution, so that makes me think the error is in your contact-form.aspx.cs page. The REAL exception should display once you add the above to your web.config.
I think your label which sits outside the form tag should be inside it see below.
<form action="" method="post" enctype="multipart/form-data" name="form1" id="form1">
<asp:label id="lblOutcome" runat="server" />
Aren't you missing the runat="server" in the form declaration?
<form id="form1" runat="server" enctype="multipart/form-data" method="post">
Also, you might be getting errors if the Namespace isn't correct, I've seen it happen, for example, after someone renamed the solution and forgot to change the namespace in all the files.
Otherwise, like the others have told you, seeing the actual error would help a lot
It looks like this sample was build using the .NET framework 1.1, is that the framework version you have set for this application on IIS? You might want to check your IIS settings to make sure the framework version is set correctly.
Hope this helps!
精彩评论