HOW TO: Accessing Config File Mail Settings Programmatically

Rate It (1)

Last post 04-05-2008 1:57 PM by TATWORTH. 24 replies.

Sort Posts:

  • Re: HOW TO: Accessing Config File Mail Settings Programmatically

    03-12-2008, 11:07 AM
    • Loading...
    • dihola
    • Joined on 11-30-2007, 2:26 PM
    • Posts 12

     Hi,

    I have followed your example and it worked, thanks. However what I want to do is to override the settings in web.config for some others,

    to persist in teh website. So I am trying to do something like this in Application_Start:

     

     Configuration configurationFile = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~/web.config");
                    System.Net.Configuration.MailSettingsSectionGroup mailSettings = configurationFile.GetSectionGroup("system.net/mailSettings") as System.Net.Configuration.MailSettingsSectionGroup;

                    if (mailSettings != null)
                    {
                        mailSettings.Smtp.Network.Port = aPort;
                        mailSettings.Smtp.Network.Host = aHost;
                        mailSettings.Smtp.Network.Password = aPassword;
                        mailSettings.Smtp.Network.UserName = aUserName;
                    }               

     

    However my changes don't persist and when I send an email it defaults to what's in web.config. Any idea what I am doing wrong? 

     

    Thanks 

  • Re: HOW TO: Accessing Config File Mail Settings Programmatically

    04-05-2008, 12:01 PM
    • Loading...
    • Uffan
    • Joined on 10-15-2007, 2:25 PM
    • ATL
    • Posts 45

    I am trying to programmatically update my UrlMappings. I have my site hosted on GoDaddy and I getting the same System.Security.Permissions.FileIOPermission security error when updating the web.config file. My code is below... it there a way to specify the security settings. Any ideas?

    Dim config As Configuration = WebConfigurationManager.OpenWebConfiguration(HttpContext.Current.Request.ApplicationPath)
    Dim section As New UrlMappingsSection
    section = config.GetSection("system.web/urlMappings")
    'section.UrlMappings.Clear()
    section.UrlMappings.Add(New UrlMapping("~/david.aspx", "~/member.aspx?memberId=30"))
    config.Save()
    
     
  • Re: HOW TO: Accessing Config File Mail Settings Programmatically

    04-05-2008, 12:47 PM
    • Loading...
    • TATWORTH
    • Joined on 02-04-2003, 1:34 PM
    • England
    • Posts 5,094

    I strongly suspect that your ASPNET account does not have write access to web.config file.

    Don't forget to click "Mark as Answer" on the post that helped you.
    This credits that member, earns you a point and marks your thread as Resolved so we will all know you have been helped.
  • Re: HOW TO: Accessing Config File Mail Settings Programmatically

    04-05-2008, 12:54 PM
    • Loading...
    • Uffan
    • Joined on 10-15-2007, 2:25 PM
    • ATL
    • Posts 45

    Is that something I should change or is it dangerous? If it is dangerous, what other options do I have to update my config file automatically. My ultimate goal is to have the site allow for new membership. Once someone has signed up and verified their email address the site activates their account. At this point I would like to programmatically update the config file. 

  • Re: HOW TO: Accessing Config File Mail Settings Programmatically

    04-05-2008, 1:00 PM
    • Loading...
    • TATWORTH
    • Joined on 02-04-2003, 1:34 PM
    • England
    • Posts 5,094

    I suggest that you save the information to the database and not try to out such information into the config file. I suspect that GODADDY have locked the permissions down as part of their security measures - if that is so, you will not be able to change the permissions yourself.

    Don't forget to click "Mark as Answer" on the post that helped you.
    This credits that member, earns you a point and marks your thread as Resolved so we will all know you have been helped.
  • Re: HOW TO: Accessing Config File Mail Settings Programmatically

    04-05-2008, 1:06 PM
    • Loading...
    • Uffan
    • Joined on 10-15-2007, 2:25 PM
    • ATL
    • Posts 45

    I save the information to the database but I want to give friendly address to each member based on their unique user name. And correct me if I am wrong but I need to use the web.config file to give the friendly address. Is there a better way to accomplish this?

  • Re: HOW TO: Accessing Config File Mail Settings Programmatically

    04-05-2008, 1:13 PM
    • Loading...
    • TATWORTH
    • Joined on 02-04-2003, 1:34 PM
    • England
    • Posts 5,094

     Is the database your own design or are you using the ASPNETDB database?

    Don't forget to click "Mark as Answer" on the post that helped you.
    This credits that member, earns you a point and marks your thread as Resolved so we will all know you have been helped.
  • Re: HOW TO: Accessing Config File Mail Settings Programmatically

    04-05-2008, 1:25 PM
    • Loading...
    • Uffan
    • Joined on 10-15-2007, 2:25 PM
    • ATL
    • Posts 45

    It is my own, when a member signs up they must use a unique email address (that they verify) and a unique user name. This info is saved in tblUsers. My wish is to create a friendly address to each member's page using their user name. Currently their address is based off the tblUsers.id

    E.g. new member 'dave' signs up then I want to programmatically create the address: http://mypage.com/dave.aspx versus http://mypage.com/members?memberId=123.

  • Re: HOW TO: Accessing Config File Mail Settings Programmatically

    04-05-2008, 1:39 PM
    • Loading...
    • Uffan
    • Joined on 10-15-2007, 2:25 PM
    • ATL
    • Posts 45

     The wife calls... I must go. Thank you for your help Tatworth, I greatly appreciated it. If you have any ideas or a better way for me to accomplish my goal please let me know. I will check back this afternoon.
     

  • Re: HOW TO: Accessing Config File Mail Settings Programmatically

    04-05-2008, 1:57 PM
    • Loading...
    • TATWORTH
    • Joined on 02-04-2003, 1:34 PM
    • England
    • Posts 5,094

     I suggest that you store the friendly name in the database and when the user logs in, put the value into a session variable for your URL rewriter to use.

    Don't forget to click "Mark as Answer" on the post that helped you.
    This credits that member, earns you a point and marks your thread as Resolved so we will all know you have been helped.
Page 2 of 2 (25 items) < Previous 1 2