 |
BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3
 | This is the forum to discuss the Wrox book Beginning ASP.NET 3.5: In C# and VB by Imar Spaanjaars; ISBN: 9780470187593 |
|
Welcome to the p2p.wrox.com Forums.
You are currently viewing the BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|
|

July 18th, 2009, 05:16 AM
|
|
Authorized User
|
|
Join Date: Apr 2009
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Chap 15 pg 535: SMTP error (requires secure connection, authentication and ssl)
Hello,
Having typed in the code out of the book from pg 534 and pg 535 I get the following error.
The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.0 Must issue a STARTTLS command first. 24sm5468485wfc.37
To address this I tried to insert the smtp details from the signup.aspx.cs but this didn't work either.
Are we supposed to set up another smtp on this project?
Help...
Cheers
Thomas
|
|

July 18th, 2009, 05:27 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Heuh? Aren't we already doing this here: Chap 15 pg 532
This is the exact same issue. Your SMTP provider requires SSL. The Login controls don't support SSL by default. These two facts combined require you to work around it by handling the SendingMail event.
Maybe we'd better continue the other thread?
And are you deliberately ignoring my remarks about your user name and password or do you not see what I am talking about?
Imar
|
|

July 18th, 2009, 05:45 AM
|
|
Authorized User
|
|
Join Date: Apr 2009
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Imar,
What we did with SignUp.aspx works fine.
It is Login.aspx that doesn't work.
I am not ignoring your advice on the password.
I couldn't see where it was a problem.
It is an account I set up for studying this book anyways.
I don't know how to edit threads so if you could enlighten me that would be great.
Regards
Thomas
|
|

July 18th, 2009, 05:52 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Quote:
What we did with SignUp.aspx works fine.
It is Login.aspx that doesn't work.
|
I understand that. However, in order for Login.aspx to send the rest password, you need to apply the exact same trick to that page: handle the SendingMail event and create your own SSL enabled SmtpClient.
Quote:
|
I don't know how to edit threads so if you could enlighten me that would be great.
|
You could try hitting that big Edit button that you see below each of your own messages when logged in...
Imar
|
|

July 18th, 2009, 08:37 AM
|
|
Authorized User
|
|
Join Date: Apr 2009
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I did the following in login.aspx.cs but the problem still is there.
I think I know why as it is because I had to code as opposed to type the sendingmail event.
I couldn't see the password recovery in design view but it was there in the code.
Why wouldn't I be able to see it in design view but I can see it in the browser?
Anyways I am getting the same tls error although it has been declared.
Any ideas?
Code:
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Net.Mail;
publicpartialclassLogin : BasePage
{
protectedvoid Page_Load(object sender, EventArgs e)
{
MailMessage myMessage = newMailMessage();
SmtpClient mySmtpClient = newSmtpClient();
myMessage.To.Add(newMailAddress("[email protected]"));
mySmtpClient.Port = 587;
mySmtpClient.Credentials = new System.Net.NetworkCredential("[email protected]", "mypassword");
mySmtpClient.EnableSsl = true;
mySmtpClient.Send(myMessage);
}
protectedvoid PasswordRecovery1_SendingMail(object sender, MailMessageEventArgs e)
{
SmtpClient mySmtpClient = newSmtpClient();
mySmtpClient.EnableSsl = true;
mySmtpClient.Send(e.Message);
e.Cancel = true;
}
}
Thanks Tomche
|
|

July 18th, 2009, 08:52 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
If you want useful help from me, please, please do the following:
1. Click the Remove Text Formatting button on the toolbar when you post code and wrap it in code tags. Without it, spaces are stripped from the code which makes it difficult to read and impossible to use.
2. Please provide specific information. I cannot do anything with a statement like "Anyways I am getting the same tls error although it has been declared.".
- When?
- Where?
- On what code exactly?
- What's the exact error message?
- In Page_Load or in PasswordRecovery1_SendingMail?
- What web.config settings are you using?
- How does the markup look for the password recovey control?
- Does your code in the code behind get hit when you set a break point?
- What's the code in Page_Load supposed to do.
- Did you manage to make the stuff we discussed in the other thread work fine without errors?
- Etc etc etc etc etc.
- And so on and so forth
Remember: this is text only. I can only see what you're providing me with which, at the moment, isn't a whole lot. So, describe your scenario and actions step by step.
Imar
|
|

July 19th, 2009, 01:10 AM
|
|
Authorized User
|
|
Join Date: Apr 2009
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Imar,
I will try and answer your questions one at a time
- What's the exact error message?
[FONT='Times New Roman','serif']The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.0 Must issue a STARTTLS command first. n40sm6522757wag.65[/font]
- When?
I happens after I have clicked the submit button on the password recovery.
- Where?
I suppose the only answer to this question is that the error message occurs in my browser.
- On what code exactly?
I can’t say exactly whether it is passwordrecovery code but considering that it happens when I use the submit button on pawwwordrecovery I woul imagine that it is the password recovery code.
- In Page_Load or in PasswordRecovery1_SendingMail?
See my answer to previous question.
- What web.config settings are you using?
The web.config code is below
- How does the markup look for the password recovey control?
Code:
protectedvoid PasswordRecovery1_SendingMail(object sender, MailMessageEventArgs e)
{
SmtpClient mySmtpClient = newSmtpClient();
mySmtpClient.EnableSsl = true;
mySmtpClient.Send(e.Message);
e.Cancel = true;
}
- Does your code in the code behind get hit when you set a break point?
If you can determine this by the exitance of two blank lines between the login control and the password recovery control then the break is being hit.
- What's the code in Page_Load supposed to do.
Declare an smtp server.
The code is below
Code:
protectedvoid Page_Load(object sender, EventArgs e)
{
MailMessage myMessage = newMailMessage();
SmtpClient mySmtpClient = newSmtpClient();
myMessage.To.Add(newMailAddress("[email protected]"));
mySmtpClient.Port = 587;
mySmtpClient.Credentials = new System.Net.NetworkCredential("[email protected]", "mypassword");
mySmtpClient.EnableSsl = true;
mySmtpClient.Send(myMessage);
}
- Did you manage to make the stuff we discussed in the other thread work fine without errors?
As mentioned the Signup.aspx works fine. I borrowed the code from there and replaed the createuserwizard1 with the passwordrecovery1 in the smtp code.
My code is as follows
My login.aspx file looks like this
Code:
<%@PageLanguage="C#"MasterPageFile="~/MasterPages/MasterPage.master"AutoEventWireup="true"CodeFile="Login.aspx.cs"Inherits="Login"Title="Log in to Planet Wrox"Debug="true" %>
<asp:ContentID="Content1"ContentPlaceHolderID="head"Runat="Server">
</asp:Content>
<asp:ContentID="Content2"ContentPlaceHolderID="cpMainContent"Runat="Server">
<asp:LoginViewID="LoginView1"runat="server">
<LoggedInTemplate>
You are already logged in
</LoggedInTemplate>
<AnonymousTemplate>
<asp:LoginID="Login1"runat="server"CreateUserText="Sign Up for a New Account at Planet Wrox Now!"CreateUserUrl="SignUp.aspx">
</asp:Login>
<br/><br/>
<asp:PasswordRecoveryID="PasswordRecovery1"runat="server">
<MailDefinitionSubject="Your New Password for PlanetWrox.Com"></MailDefinition>
</asp:PasswordRecovery>
</AnonymousTemplate>
</asp:LoginView>
<asp:LoginStatusID="LoginStatus1"runat="server"/>
</asp:Content>
My login.aspx.cs looks like this
Code:
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Net.Mail;
publicpartialclassLogin : BasePage
{
protectedvoid Page_Load(object sender, EventArgs e)
{
MailMessage myMessage = newMailMessage();
SmtpClient mySmtpClient = newSmtpClient();
myMessage.To.Add(newMailAddress("[email protected]"));
mySmtpClient.Port = 587;
mySmtpClient.Credentials = new System.Net.NetworkCredential("[email protected]", "mypassword");
mySmtpClient.EnableSsl = true;
mySmtpClient.Send(myMessage);
}
protectedvoid PasswordRecovery1_SendingMail(object sender, MailMessageEventArgs e)
{
SmtpClient mySmtpClient = newSmtpClient();
mySmtpClient.EnableSsl = true;
mySmtpClient.Send(e.Message);
e.Cancel = true;
}
}
My web config looks like this
Code:
<configuration>
<configSections>
<sectionGroupname="system.web.extensions"type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<sectionGroupname="scripting"type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<sectionname="scriptResourceHandler"type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"requirePermission="false"allowDefinition="MachineToApplication"/>
<sectionGroupname="webServices"type="System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<sectionname="jsonSerialization"type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"requirePermission="false"allowDefinition="Everywhere"/>
<sectionname="profileService"type="System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"requirePermission="false"allowDefinition="MachineToApplication"/>
<sectionname="authenticationService"type="System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"requirePermission="false"allowDefinition="MachineToApplication"/>
<sectionname="roleService"type="System.Web.Configuration.ScriptingRoleServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"requirePermission="false"allowDefinition="MachineToApplication"/>
</sectionGroup>
</sectionGroup>
</sectionGroup>
</configSections>
<appSettings/>
<connectionStrings>
<addname="PlanetWroxConnectionString1"connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\PlanetWrox.mdf;Integrated Security=True;User Instance=True"providerName="System.Data.SqlClient"/>
</connectionStrings>
<system.web>
<!--
Set compilation debug="true" to insert debugging
symbols into the compiled page. Because this
affects performance, set this value to true only
during development.
-->
<compilationdebug="false">
<assemblies>
<addassembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<addassembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<addassembly="System.Data.DataSetExtensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<addassembly="System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<addassembly="System.Data.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
</assemblies>
</compilation>
<!--
The <authentication> section enables configuration
of the security authentication mode used by
ASP.NET to identify an incoming user.
-->
<authenticationmode="Forms"/>
<!--
The <customErrors> section enables configuration
of what to do if/when an unhandled error occurs
during the execution of a request. Specifically,
it enables developers to configure html error pages
to be displayed in place of a error stack trace.
<customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
<error statusCode="403" redirect="NoAccess.htm" />
<error statusCode="404" redirect="FileNotFound.htm" />
</customErrors>
-->
<pagestheme="Monochrome">
<controls>
<addtagPrefix="Wrox"tagName="Banner"src="~/Controls/Banner.ascx"/>
<addtagPrefix="asp"namespace="System.Web.UI"assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<addtagPrefix="asp"namespace="System.Web.UI.WebControls"assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</controls>
</pages>
<httpHandlers>
<removeverb="*"path="*.asmx"/>
<addverb="*"path="*.asmx"validate="false"type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<addverb="*"path="*_AppService.axd"validate="false"type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<addverb="GET,HEAD"path="ScriptResource.axd"type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"validate="false"/>
</httpHandlers>
<httpModules>
<addname="ScriptModule"type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</httpModules>
</system.web>
<system.codedom>
<compilers>
<compilerlanguage="c#;cs;csharp"extension=".cs"warningLevel="4"type="Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<providerOptionname="CompilerVersion"value="v3.5"/>
<providerOptionname="WarnAsError"value="false"/>
</compiler>
<compilerlanguage="vb;vbs;visualbasic;vbscript"extension=".vb"warningLevel="4"type="Microsoft.VisualBasic.VBCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<providerOptionname="CompilerVersion"value="v3.5"/>
<providerOptionname="OptionInfer"value="true"/>
<providerOptionname="WarnAsError"value="false"/>
</compiler>
</compilers>
</system.codedom>
<!--
The system.webServer section is required for running ASP.NET AJAX under Internet
Information Services 7.0. It is not necessary for previous version of IIS.
-->
<system.webServer>
<validationvalidateIntegratedModeConfiguration="false"/>
<modules>
<removename="ScriptModule"/>
<addname="ScriptModule"preCondition="managedHandler"type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</modules>
<handlers>
<removename="WebServiceHandlerFactory-Integrated"/>
<removename="ScriptHandlerFactory"/>
<removename="ScriptHandlerFactoryAppServices"/>
<removename="ScriptResource"/>
<addname="ScriptHandlerFactory"verb="*"path="*.asmx"preCondition="integratedMode"type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<addname="ScriptHandlerFactoryAppServices"verb="*"path="*_AppService.axd"preCondition="integratedMode"type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<addname="ScriptResource"preCondition="integratedMode"verb="GET,HEAD"path="ScriptResource.axd"type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</handlers>
</system.webServer>
<runtime>
<assemblyBindingxmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentityname="System.Web.Extensions"publicKeyToken="31bf3856ad364e35"/>
<bindingRedirectoldVersion="1.0.0.0-1.1.0.0"newVersion="3.5.0.0"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentityname="System.Web.Extensions.Design"publicKeyToken="31bf3856ad364e35"/>
<bindingRedirectoldVersion="1.0.0.0-1.1.0.0"newVersion="3.5.0.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
<system.net>
<mailSettings>
<smtpdeliveryMethod="Network"from="Your Name <[email protected]>">
<networkhost="smtp.gmail.com"port="587"userName="stemcell74"password="password"/>
</smtp>
</mailSettings>
</system.net>
</configuration>
There are no parse errors on any of the code in VWD.
I think the problem is with the fact that I can’t get the passwordrecovery to display in design view in Visual Web Developer.
Therefore I can’t right click to establish the sendingmail event in the propertis grid.
I tried to do it via code but I am not sure I got it right
I have used the code tags and also hit the remove formatting button
Regards
Thomas
Last edited by tomche; July 19th, 2009 at 01:16 AM..
|
|

July 19th, 2009, 01:54 AM
|
|
Authorized User
|
|
Join Date: Apr 2009
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I worked it out.
My suspisions were confirmed.
The login.aspx need this line.
<asp:PasswordRecoveryID="PasswordRecovery1"runat="server"OnSendingMail="PasswordRecovery1_SendingMail">
I was missing the OnSendingMail="passwordrecovery1 declaration.
Cheers
Thomas
|
|

July 19th, 2009, 04:10 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Hi tomche,
Maybe you were not seeing the PasswordRecovery control because the LoginView was showing the LoggedIn template? Did you just see the text "You are already logged in"? If so, open the LoginView's Smart Task Panel and choose Anonymous Template from the Views drop down. If I do that, I can access the PasswordRecovery control just fine.
And yes, you're right about the fix. You can define a method in code behind but that doesn't mean it gets called automatically. You need to hook up the control to the method using the OnSendingMail attribute.
If you had provided this much detail in the first place, this question could have been solved some time ago. I was maybe exaggerating a bit with the number of questions I asked, but really, the more details the better; especially when code is involved.
Quote:
|
and also hit the remove formatting button
|
That's not working too well. There's a (stupid and apparently hard to fix) bug in this forum's editor that messes up color coded code. Take a look at your markup for the Login for example, or the web.config file. All spaces are gone. For example, you get <authenticationmode="Forms"/> instead of <authentication mode="Forms"/>. If you post more code in the future, please take a look at it before you post and see if it's OK. I usually use the Remove Text Formatting button to remove color coding or paste in Notepad first and copy it from there, just to be sure....
Quote:
|
- Does your code in the code behind get hit when you set a break point?
|
I meant a code breakpoint. In Code Behind, press F9 on a line you want the program to halt on (like the first line of code in Page_Load). Then press F5 to start debugging. Debugging is discussed in detail in chapter 17.
Anyway, glad it's all working now.
Cheers,
Imar
|
Similar Threads
|
| Thread |
Thread Starter |
Forum |
Replies |
Last Post |
| Chap 15 pg 532 |
tomche |
BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 |
10 |
April 2nd, 2010 03:37 PM |
| listing 15-15 pg(568) |
DyerOppenheimer |
BOOK: Professional ASP.NET 2.0 and Special Edition; ISBN: 978-0-7645-7610-2; ISBN: 978-0-470-04178-9 |
0 |
February 13th, 2008 01:41 PM |
| MySQL Fatal Error Chap 3, Pg 96-96 |
joshkosmala |
BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 |
2 |
January 8th, 2007 01:55 PM |
| Chap 15 (p.579) Connection string to SQL Server |
Venboy |
BOOK: Professional ASP.NET 2.0 and Special Edition; ISBN: 978-0-7645-7610-2; ISBN: 978-0-470-04178-9 |
0 |
July 23rd, 2006 10:56 AM |
| Secure SQL Server authentication |
sal |
ASP.NET 1.x and 2.0 Application Design |
3 |
October 17th, 2004 04:02 PM |
|
 |