Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0Updating web.config from custom module packageUpdating web.config from custom module package
Previous
 
Next
New Post
6/3/2008 6:28 PM
 

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 7:11 PM
 

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


Buy the new Professional DNN7: Open Source .NET CMS Platform book Amazon US
 
New Post
6/4/2008 4:44 AM
 

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

 
New Post
6/5/2008 12:21 PM
 

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 12:26 PM
 

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
 
Next
HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0Updating web.config from custom module packageUpdating web.config from custom module package


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, 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 DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out