Small width layout Medium width layout Maximum width layout Small text Medium text Large text
     Search
Downloads Downloads Directory Directory Forums Forums Forge Forge Blogs Blogs        Marketplace Marketplace Careers Program Careers
Community › Forums Register  |  

AppTheory specializes in solutions based on the DotNetNuke platform and has 2 employees on the DotNetNuke Core Team.
  Ads  
Active Modules -- Active Forums for DotNetNuke
 


  Sponsors  

Meet Our Sponsors

.: CounterSoft :.
telerik
ExactTarget email software solutions
Merak Mail Server
WebSecureStores -- ASP.NET & DotNetNuke Hosting Solutions
FCKeditor Project
 


DotNetNuke Forums
 
  Forum  General DotNetN...  Extend It! ( Pr...  Updating web.config from custom module package
Previous Previous
 
Next Next
New Post 6/3/2008 4:28 PM
Unresolved
User is offline Scott Brayer
4 posts
10th Ranked


Updating web.config from custom module package 

Hi.

I'm new to DNN custom modules.  I created a module that needs to access multiple data sources.  The code all works great, but now I want to package it so I can deploy it on multiple DNN sites.  I was able to create the package very easily from within DNN.  However, I can't figure out how to get the package to modify web.config to add new database connection strings etc...  I noticed that the package that DNN created did add a line in web.config to let .Net know that my module was written in C# rather than VB, so I would think there would be a way to do this.  If anyone could point me in the right direction, that would be great!

 
New Post 6/3/2008 5:11 PM
User is offline cathal connolly
2756 posts
www.cathal.co.uk
5th Ranked










Re: Updating web.config from custom module package 

we used to use some custom xpath code for that, but with 4.6 we wrapped it up in a core method that can be used by module developers - see http://www.dotnetnuke.com/Community/Blogs/tabid/825/EntryID/1844/Default.aspx for a starter on using it.

Cathal

 
New Post 6/4/2008 2:44 AM
User is offline FreeDotNetNuke
156 posts
freedotnetnuke.com
9th Ranked


Re: Updating web.config from custom module package 

Scott

We have used structure like this:

    string WebConfigFileName =
     Server.MapPath(Request.Url.AbsolutePath).ToLower().Replace("default.aspx","web.config");
    System.Xml.XmlDocument objDoc = new System.Xml.XmlDocument();
    objDoc.Load(WebConfigFileName);
    System.Xml.XmlNode objHttpModules = objDoc.DocumentElement["system.web"]["httpModules"];
    bool Exists = false;
    foreach(System.Xml.XmlNode objNode in objHttpModules.ChildNodes)
    {
     if(objNode.Attributes!=null)
     {
      if(objNode.Attributes["name"]!=null)
      {
       if(objNode.Attributes["name"].Value=="OurName")
       {
        Exists = true;
        break;
       }
      }
     }
    }

    if(!Exists)
    {
     System.Xml.XmlNode objAdd = objDoc.CreateElement("add");
     
     System.Xml.XmlAttribute objName = objDoc.CreateAttribute("name");
     objName.Value = "OurName";

     System.Xml.XmlAttribute objType = objDoc.CreateAttribute("type");
     objType.Value = "OurValue";

     objAdd.Attributes.Append(objName);
     objAdd.Attributes.Append(objType);
     objHttpModules.AppendChild(objAdd);

     try
     {
      objDoc.Save(WebConfigFileName);
     }
     catch(Exception Exc)
     {
      DotNetNuke.Skin.AddModuleMessage(this,"web.config updates error "+Exc.Message,
       DotNetNuke.UI.Skins.Controls.ModuleMessage.ModuleMessageType.RedError);
     }
    }

Hope it helps.

Sergey


Client always right!
Pages Administration with Drag&Drop for DotNetNuke
List Of All Modules From FreeDotNetNuke
 
New Post 6/5/2008 10:21 AM
User is offline Scott Brayer
4 posts
10th Ranked


Re: Updating web.config from custom module package 

Cathal,

This seems to be exactly what I am looking for.  However, I added the following XML to my module's manifest file (as a child of the dotnetnuke node) and when I run the install it seems to be ignored.  Any idea of what I am missing?

<config>
    <configFile>web.config</configFile>
    <install>
        <configuration>
           <nodes>
               <node path="/configuration/connectionStrings" action="update" key="name" collision="overwrite">
                   <add name="WeatherSqlServer" connectionString="Data Source=someserver;Initial Catalog=WEATHER;Persist Security Info=True;User ID=myuser;Password=thepassword" providerName="System.Data.SqlClient"/>
               </node>
               <node path="/configuration/connectionStrings" action="update" key="name" collision="overwrite">
                   <add name="WeatherImgSqlServer" connectionString="Data Source=anotherserver;Initial Catalog=AnotherDB;Persist Security Info=True;User ID=anotheruser;Password=anotherpassword" providerName="System.Data.SqlClient"/>
               </node>
           </nodes>
        </configuration>
    </install>
    <uninstall>
        <configuration>
           <nodes>
               <node path="/configuration/connectionStrings/add [@name='WeatherSqlServer']" action="remove" />
               <node path="/configuration/connectionStrings/add [@name='WeatherImgSqlServer']" action="remove" />
           </nodes>
        </configuration>
    </uninstall>
</config>

Thanks again for all of your help!!!

Scott

 
New Post 6/5/2008 10:26 AM
User is offline Scott Brayer
4 posts
10th Ranked


Re: Updating web.config from custom module package 

Hi Sergey,

Thank you for the reply.  All of your code here seems to make sense, but where does it reside such that it gets invoked when the module is being installed?  Thanks again for the response.  I really appreciate your help.

Scott

 
Previous Previous
 
Next Next
  Forum  General DotNetN...  Extend It! ( Pr...  Updating web.config from custom module package
 


Forum Policy

These Discussion Forums are dedicated to the discussion of the DotNetNuke Web Application Framework.

For the benefit of the community and to protect the integrity of the project, please observe the following posting guidelines:

1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DotNetNuke.
2. Discussion or promotion of DotNetNuke product releases under a different brand name are strictly prohibited.
3. No Flaming or Trolling.
4. No Profanity, Racism, or Prejudice.
5. Site Moderators have the final word on approving/removing a thread or post or comment.
6. English language posting only, please.

 


Viva Portals, L.L.C.
Expert module development and graphic design.
www.continure.com
DNN Photo Gallery
DNN Photo Gallery is a truly unique photo management module released January 1st 2006. With DNN Photo Gallery you can REALLY integrate images into your existing portal and make them look like they were designed for your site.
DNN Photo Gallery
Swirlhost Inc.
Affordable DotNetNuke Hosting, Skin Development, Custom Module Development, and DotNetNuke Consulting. We will install your preference of DNN and now host with us and get a free license for the Swirl AJAX Chatroom Module.
www.swirlhost.com

DotNetNuke Corporation   Terms Of Use  Privacy Statement
DotNetNuke®, DNN®, and the DotNetNuke logo are trademarks of DotNetNuke Corporation
Hosted by MaximumASP