Building the dotnetnuke module in normal Asp.net Application

Source: Internet
Author: User
Tags dnn dotnetnuke

Supported by Nova Outsourcing

 

Before writing the article, I have thought it a while that if it is necessary to share the way of building dotnetnuke module in normal Asp.net application. this case may be rare or no body has ever plan to do it.

It is marvellous to me that I run into this situation. the project was required to be developed in normal Asp.net web form. just in half way, it was required to be developed on the dotnetnuke framework. I felt disappointed at that time. but now I am using ved from that situation. the list below are summarized from that situation.

    1. Create the folder structure that will be identical in the dnn deployment
    2. Inherit from the dnn base classes
    3. Multi-lingual consideration

 

Create the folder structure that will be identical in the dnn deployment

Of course, we start from creating a normal Asp.net application project instead of the dnn module which is at the top. It is recommended that the project name wocould be identical to the module name in dnn.

After the project is created, you can remove the unused files/folders created by the Project template. However, it wocould be no harm if you keep them in the project.

Then we create the folders that is identical to the dnn deployment.

Then you place the Asp.net user control and other files in the folder. After the user control has been created, you can put them to the default. aspx to run instead of the dnn environment.

This approach is quite useful when your module is quite complex that is broken to several user controls to carry out of the business.

Default. aspx

 <% @  Page  Title  = "Home page"  Language  = "C #"  Masterpagefile  = "~ /Site. Master"  Autoeventwireup  = "True"  Codebehind  = "Default. aspx. cs"  Inherits  = "Tapechartingmodule. _ default"  %> <%  @  Register Tagprefix  = "Ctrl"  Tagname  = "Tapechartcontrol"  SRC  = "~ /Topics topmodules/tapechartingmodule/tapechartcontrol. ascx"  %>  <  ASP  :  Content  ID  = "Headercontent"  Runat  = "Server"  Contentplaceholderid = "Headcontent"> </  ASP  :  Content  > <  ASP  :  Content  ID  = "Bodycontent"  Runat  = "Server"  Contentplaceholderid  = "Maincontent"> <  CTRL  :  Tapechartcontrol ID  = "_ Tapechartcontrol"  Runat  = "Server"/> </  ASP  :  Content  > 

 

So you can run the project directly for tapechartcontrol. ascx to debug and test the business. And you will find it is much easier than doing it in dnn environment.

 

Inherit from the dnn base classes

Conceptually speaking, the module can be shared with other normal Asp.net application project. But our aim here is to put it in dnn site.

Only several base classes from the dnn will be added. Here they are listed below.

    1. Portmodulebase
    2. Iactionable
    3. Modulesettingsbase

Actually, if you just want to represent the data on the panel, you even don't need to inherit modulesettingsbase to create the settings panel.

Here is the sample code for tapechartcontrol. Please add reference to dotnetnuke. dll in your project as well.

 Using System; Using System. Collections. Generic; Using System. LINQ; Using System. Web; Using System. Web. UI; Using System. Web. UI. webcontrols; Using Dotnetnuke. Entities. modules;Using Dotnetnuke. Entities. modules. actions; Namespace Tapechartingmodule { Public partial class  Tapechartcontrol : Portalmodulebase , Iactionable { Protected void Page_load ( Object Sender, Eventargs E ){} Public Dotnetnuke. Entities. modules. Actions. Moduleactioncollection Moduleactions { Get { Moduleactioncollection Actions = New  Moduleactioncollection (); Return Actions ;}}}}

Other code in the control wocould be normal Asp.net C # code. So they are ignored here.

 

Multi-lingual consideration

Although multi-lingual consideration is optional here, you can't ignore it if it is required. conceptually speaking, the multi-lingual is just one of features in globalization domain. however, dotnetnuke removes the implementation in normal Asp.net application and builds its own implementation for globalization. so the following code in ascx will not work in dotnetnuke environment.

 
<ASP:ButtonID= "_ Addbutton"Runat= "Server"Text="<%$Resources: add%>"/>

Or

 
<ASP:ButtonID= "_ Addbutton"Runat= "Server"Text= "Add"Meta:Resourcekey= "Add"/>

 

The globalization in dotnetnuke is implemented as following.

<ASP:ButtonID= "_ Addbutton"Runat= "Server"Text= "Add"Resourcekey= "Add"/>

 

If you dig into the dotnetnuke source code about localization, you will find that its globalization involves portal information which explains why the implementation of globalization in dotnetnuke and normal Asp.net are essential different.

 

To implement the multi-lingual feature in both Asp.net application and dotnetnuke, We wocould build a new expression builder. The Code applying expression builder runs as following.

 
<ASP:ButtonID= "_ Addbutton"Runat= "Server"Text="$Dic: add%>"/>

 

Then you shoshould create a dic. resx or DIC. [region-Code]. resx and put it in the root/app_globalresources folder of the dotnetnuke site.

Here I will not explain more about expression builder, you can refer the source code of DIC in dev3lib project or the link at msdn

 

Eventually, you have to run the module in dotnetnuke environment, please refer to "start to dotnetnuke module development: 2 and 3" if you have needs to debug in dotnetnuke environment.

I am not sure if the above 3 points are best practice to make the user control work in both Asp.net application and dotnetnuke environment, I will appreciate of your ideas on the solutions.

 

Supported by Nova Outsourcing

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.