DotNetNuke CSharp Web Application Project

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

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 Dialog

As per my usual process, I created a folder named ExternalDependencies in the project and copied all the DNN assemblies from the Installation distribution (DotNetNuke_4.0.3_Install.zip) 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 Menu

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.

Download

To save you some time I am including the barebone solution and project here based on the DNN 4.0.3 distribution.

Keep in mind that this is a “pre-install” project meaning that after you set it up, you will need to rename release.config to web.config and update the connection string settings to point to your database. Afterwards, hit CTRL+F5 and walk through the DNN web-based installation process. That process will make filesystem changes so make sure you have appropriate write access.

Let me know if this works for you or if you find any mistakes, problems, issues with it.

What others have said

Requesting Gravatar... Liang May 18, 2006 11:17 AM
# re: DotNetNuke CSharp Web Application Project
Thanks! But the download link does not work.
Requesting Gravatar... Haacked May 18, 2006 4:11 PM
# re: DotNetNuke CSharp Web Application Project
Make sure your firewall doesn't block port 8080. I'm using the Coral Distribution Network.
Requesting Gravatar... Michael Freidgeim May 19, 2006 6:59 AM
# re: DotNetNuke CSharp Web Application Project
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(http://geekswithblogs.net/mnf/archive/2006/03/03/71229.aspx).

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.
Requesting Gravatar... Cathal May 19, 2006 9:30 AM
# re: DotNetNuke CSharp Web Application Project
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 vs.net 2005, I've used it on the release version without issue.
Requesting Gravatar... Haacked May 19, 2006 10:21 AM
# re: DotNetNuke CSharp Web Application Project
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.
Requesting Gravatar... Rodney Joyce May 24, 2006 6:31 PM
# re: DotNetNuke CSharp Web Application Project
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!
Requesting Gravatar... Aaron Prenot May 30, 2006 7:48 AM
# re: DotNetNuke CSharp Web Application Project
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.
Requesting Gravatar... Haacked May 30, 2006 8:35 AM
# re: DotNetNuke CSharp Web Application Project
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.
Requesting Gravatar... stew Jun 21, 2006 10:54 PM
# re: DotNetNuke CSharp Web Application Project
ur invistigtion does not work

it did not created any .dnn file which is needed to upload the module on a dn server
Requesting Gravatar... anuj Oct 23, 2006 9:09 PM
# re: DotNetNuke CSharp Web Application Project
Hi,
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
Requesting Gravatar... Kevin Castle .Net Nov 10, 2006 12:52 AM
# DotNetNuke Never to Support Web Application Projects
Requesting Gravatar... SanthU May 30, 2008 8:07 PM
# re: DotNetNuke CSharp Web Application Project
Hi,

I have an shopping cart project in ASP.net 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
Requesting Gravatar... jaspal singh Sep 29, 2008 9:06 PM
# re: DotNetNuke CSharp Web Application Project
well i read all stuff given above .... plzz tell me how can i use dnn in my asp.net application.... plzz reply to my email id .... as soon as possible..!!
Requesting Gravatar... life insurance Dec 10, 2008 8:53 PM
# re: DotNetNuke CSharp Web Application Project
please help me for what you mean by project?
how to implement the csharp codings and connecting to the sql server?
Requesting Gravatar... arulbaskar Dec 08, 2010 12:23 AM
# re: DotNetNuke CSharp Web Application Project
please help me for what you mean by project?
how to implement the csharp codings and connecting to the sql server?

What do you have to say?

(will show your gravatar)
Please add 4 and 2 and type the answer here: