Search code examples
moduleweb-configdotnetnuke

How to prevent auto generated web.config into my dnn module project?


I have developed DotNetNuke module using DotNetNuke C# Compiled Module Template in Visual Studio 2010. My module project is located under DesktopModules section in dnndev.

When I am designing any .ascx page(View.ascx) its automatically adding a web.config file in my project location. But I already have a web.config file where my dnndev is hosted and for conflicting two web.config file, I think there is being loading problem of my custom module in dnndev page.

My question is How to prevent auto generated web.config into my dnn module project? And How to read connection string from external web.config(dnndev hosted web.config) for my module project?


Solution

  • The connection string is stored in the default connection string collection, and DNN provides a few methods to get to it as well. Here are a few options.

    • ConfigurationManager.ConnectionStrings["SiteSqlServer"].ConnectionString
    • DataProvider.Instance().ConnectionString - if Using DAL+
    • From within the SqlDataProvider.cs file in your template if using the older DAL method

    As for your issue with the web.config. Typically the only time that this gets added by Visual Studio is if you change the compilation target. Visual Studio sees a web project and assumes that you need a web.config. You can just delete it and it shouldn't come back.