DotNetNuke CSharp Web Application Project

DNN DotNetNuke 0 comments suggest edit


Better grab this before they take away my DNN license. But first, let me give you a bit of background.


Past versions of DotNetNuke typically came with a source code release and an installation release. Many developers (myself included) look at DNN as a platform and prefer not to touch the DNN source code. Once you start tweaking the source code, you open up a world of headaches if you plan on upgrading to the next version of DNN since you add the pain of making sure to migrate your own changes. DNN provides plenty of integration and extensibility points that for the most part, touching the source code is unnecessary.

Instead, I set up my projects to only reference the DNN assemblies and include the *.aspx, *.ascx, etc… files without the code behind. If you’ve worked with DNN before, you may be familiar with the My Modules technique which included the famous _DNNStub project.

But now comes ASP.NET 2.0 which introduces a new web project model. To put it mildly, there was a bit of a negative reaction in some circles of the community around this new project model, which to be fair, serves its purpose but is not for everybody.

Naturally, when DNN 4.* was released, it was built upon this new model. Unfortunately for module developers used to the existing manner of development, the recommended method for developing modules now involves adding code directly into the special App_Code directory of the DNN web project. Shaun Walker, the creator and maintainer of DNN, wrote up a helpful guide to module development for DNN 4.* using the new Starter Kits.

Web Application Projects Introduced

But now that Microsoft released the new ASP.NET 2.0 Web Application Projects model, I thought there had to be a better way to develop modules that took advantage of the Web Application projects and was more in line with the old manner of doing it. I figured it couldn’t be that hard.

Also, I wanted to take advantage of the WebDev.WebServer (aka Cassini) that comes with VS.NET 2005. Shaun had mentioned that they had problems with running DNN using it, but I had to see for myself. The benefits of a completely self-contained build as well as being able to run the local development site on a webroot (for example http://localhost:8080/) on WinXP was well worth an attempt.

Web Application Projects Unleashed

So after installing the Web Application Project templates and add-in, I created a new web application project in VS.NET. To give myself a bit of a challenge (and since I may decide to add a custom page for some reason later), I chose to create a C# project as shown in the screenshot.

New Web Application Project

As per my usual process, I created a folder named ExternalDependencies in the project and copied all the DNN assemblies from the Installation distribution ( into that folder (this is just the way I roll). To add those assemblies as assembly references, I right-clicked the project, selected Add Reference, and then selected all the assemblies in that folder.

Add Reference Dialog

The next step was to add the special App_GlobalResources folder to the project by simply right clicking on the project and selecting Add | Add ASP.NET Folder | App_GlobalResources.

Adding Global Resources Context

After copying the contents of App_GlobalResources from the installation distribution into that folder, I copied all the other non-code files, *.ascx, *.aspx etc… into the project. At this point I am almost done getting the basic project tree setup. The one last issue to deal with is the code behind for Global.asax. Even with an installation distribution of DNN 4, this is included because under the Web Site project model, it gets compiled at runtime (unless pre-deploying). Personally I think this code could be put in an HttpModule. In any case, I translated the file into C#. This was actually a bit trickier than I expected because of the use of Global variables.

After completing these steps, I renamed release.config to web.config, updated the connection string, and hit CTRL+F5. The WebDev.Webserver started up pointing to the web application project using the URL http://localhost:2334/ (your results may vary) and it all worked!

One major benefit to using WebDev.WebServer is that getting this site running on a new development machine takes one less step. No need to futz around with IIS. Not only that, since I do my development on Windows XP which only allows one website, I used to have to develop DNN sites in a virtual application. This caused a problem when deploying the site because static image and css file references had to be updated.

With this approach, my URLs on my dev server match the URLs in the production site. One caveat to be aware of is that this approach only works if you are not using any special features of IIS. I recommend testing on a staging server that is running IIS before deploying to a production server with IIS. I only use Cassini for development purposes, not to actually host a site.

Module Development

I went ahead and added some pre-existing modules to the project (upgrading them to .NET 2.0) as separate projects. I was able to add project references from my Web Application Project to the individual module projects. As far as I can tell, there is no longer the need to have a BuildSupport project with this approach.

Found a typo or error? Suggest an edit! If accepted, your contribution is listed automatically here.



14 responses

  1. Avatar for Liang
    Liang May 18th, 2006

    Thanks! But the download link does not work.

  2. Avatar for Haacked
    Haacked May 18th, 2006

    Make sure your firewall doesn't block port 8080. I'm using the Coral Distribution Network.

  3. Avatar for Michael Freidgeim
    Michael Freidgeim May 19th, 2006

    Thanks for the post.
    But it's only for binary core( DotNetNuke_4.0.3_Install).
    What is about converting Source DNN project to WAP?
    I am able to use Cassini with DNN4.0 web site project. But you need to specify static port(
    You also mentioned that you "able to add project references from my Web Application Project to the individual module projects." But it is against the idea of dynamic loading of custom modules,why BuildSupport projects were introduced.

  4. Avatar for Cathal
    Cathal May 19th, 2006

    the coreteam have been discussing this recently to see if we can support both models. We feel it's key to support the existing model, as it allows developers to use the free visual web developer express, which is important, but would also like to support WAP as well. Ideally we'll be able to automate the conversion between the 2 models. Shaun should be blogging the details once we've evaluated it.
    By the way, I believe Shaun experienced the problems with cassini with a pre-release version of 2005, I've used it on the release version without issue.

  5. Avatar for Haacked
    Haacked May 19th, 2006

    Thanks for chiming in Cathal and Michael. I am running into minor issues deploying my site using Web Deployment Projects. I'm still digging into it.

  6. Avatar for Rodney Joyce
    Rodney Joyce May 24th, 2006

    Hmmm - out of interest - what type of projects do you make your custom modules? I used to have mine as class libraries in DNN 3.x, but now I am hitting a few issues. Do you make your modules Web App projects too?
    Thanks for the investigation!

  7. Avatar for Aaron Prenot
    Aaron Prenot May 30th, 2006

    I was wondering if you ever managed to get the web deployment projects to work correctly with the WAP model. I made some attemps, but it seems that it is having issues with namespaces not being imported. I have considered adding the necessary "Imports", but I am trying to not modify the code.

  8. Avatar for Haacked
    Haacked May 30th, 2006

    I ended up not using the Web Deployment Projects because of a weird issue with Global.asax. There is some discussion in the DNN forums about this issue.

  9. Avatar for stew
    stew June 21st, 2006

    ur invistigtion does not work
    it did not created any .dnn file which is needed to upload the module on a dn server

  10. Avatar for anuj
    anuj October 23rd, 2006

    Can u plz tell me how to create a new project/website with dotnetnuke4. Also, how and where these files are created and stored, as shown in demo.
    How can we deploy the project developed in dotnetnuke.
    I m in need of this...
    Plz help me as sppn as possible.
    Thanks & Regards
    Anuj Vohra

  11. Avatar for SanthU
    SanthU May 30th, 2008

    I have an shopping cart project in 3.5 in c# coding. How will I make this project as a module with sqlserver 2005 database itself. Is there any plugins for C# in dotnetnuke 4.x

  12. Avatar for jaspal singh
    jaspal singh September 29th, 2008

    well i read all stuff given above .... plzz tell me how can i use dnn in my application.... plzz reply to my email id .... as soon as possible..!!

  13. Avatar for life insurance
    life insurance December 10th, 2008

    please help me for what you mean by project?
    how to implement the csharp codings and connecting to the sql server?

  14. Avatar for arulbaskar
    arulbaskar December 7th, 2010

    please help me for what you mean by project?
    how to implement the csharp codings and connecting to the sql server?