I am fully aware that the system.net section of web.config typically looks something like this:
<network host="smtp_server_address" userName="myUsername" password="myPassword" />
If web.config is so populated then this info is used for sending e-mails generally and also by the Password Recovery control of the Memberships Login facility.
But I have a situation where the one web app will be installed on several different servers and managed by people with different skill levels. So rather than getting them to mess around in that mailSettings section I've instead found it better to setup 3 application variables in web.config:
<add key="SMTPserver" value="smtp_server_address" />
<add key="SMTPusername" value="myUsername" />
<add key="SMTPpassword" value="myPassword" />
And have no mailSettings area at all.
The problem I'm experiencing is how to get code within the Password Recovery page to programmatically utilize these application variables. My first inclination was to just build mailSettings on-the-fly following this guidance: http://forums.asp.net/t/1037680.aspx But when it came to saving it, it wouldn't allow me to do it. I suppose this is a security feature.
The other approach is to intercept the "SendingMail" event of Password Recovery such as is described here: http://forums.asp.net/p/1227533/2206498.aspx It's more convoluted but does work.
I'm curious to learn if anyone has come up with a cleaner solution.
I seem to have found a solution here: http://www.aspnetpro.com/newsletterarticle/2007/02/asp200702jk_l/asp200702jk_l.asp
I don't know what I was doing wrong before but now the following code works perfectly when placed in Global.asax:
void Application_Start(object sender, EventArgs e)
UpdateMailSettings(); // Modifies the MailSettings portion of web.config
System.Configuration.Configuration config = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~");
System.Net.Configuration.MailSettingsSectionGroup mailSettings = (System.Net.Configuration.MailSettingsSectionGroup)config.GetSectionGroup("system.net/mailSettings");
mailSettings.Smtp.Network.Host = BusinessObjects.Tools.GetAppSettingsValue("SMTPserver");
mailSettings.Smtp.Network.UserName = BusinessObjects.Tools.GetAppSettingsValue("SMTPusername");
mailSettings.Smtp.Network.Password = BusinessObjects.Tools.GetAppSettingsValue("SMTPpassword");
Before, the code failed at config.Save(). I'm aware that the application restarts when web.config is restarted but that's fine. What it allows me to do is instruct is instruct the assorted web admins to modify the specific app keys and then everything takes care of itself:
<add key="SMTPserver" value="shawmail.vc.shawcable.net"/>
<add key="SMTPusername" value=""/>
<add key="SMTPpassword" value=""/>
Hope this helps someone else!
You need to read this thread completely http://forums.asp.net/t/1250771.aspx?PageIndex=2
There is same scenario like yours. There is no need to use password recovery built in control. You can write your own. which will fetch the USer Name , Security question , answer or reseet the password etc.
Let me know if you have any query.
Watch The true story of internet ||Yet another forum |||
I'm big fan of Open source flash chart for .net very very simple
I n t e r v i e w T i p s
Thank you for responding. Yes, I'm aware that I could build my own Login facility. And I did so with ASP.Net 1.0. But why would I do so now? I'd love to hear the opinions of other developers on this.
As my previous post indicated, I added some simple code to Global.asax and now I have the Password Recovery control working perfectly!
As far as I know, your solutions are fine. We can either use PasswordRecovery's SendingMail event to send email or modify web.config in Application_Start event.
Microsoft Online Community Support
Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question.