Saturday, December 11, 2010

Using master pages and aspx pages in dnn

In this post, we are going to see how we can add new aspx pages by re-using the existing skin designs to implement some helpfull programming in it.


Why?


If you are running a multi-portal dnn website and want to build some common pages to share between those portals, there are couple of quick ways to do that.

  1. 1. Create a new tab in portal 0 and then share link in all other portals.
    This technique works fine when you want to show "how to" page or help page, static contents or offers related pages. You don't need any custom coding for this and it will be a matter of adding a text html module and paste the html that you designed!
  2. 2. Create a new aspx page and share link in all other portals.
    Well, this one also looks similar to first option but let's think about this: If you are running a multi-portal dnn site and want to show latest offers from all the portals into a page based on user's country, and users having at least 5 orders in history. Now, this will involve some quick coding to do. So, basically, if you want to show content based on some dynamic parameters like user or portal data or similar data, it will be good to create an aspx page.
There is another option! obviously you can create a new module to do this, but remember that we are not doing anything that depends on moduleId or tabId but depends on UserId or PortalId, so I believe it's a quick way to create a new page in place of building an entire dnn module.

How?

  1. 1. Create a new theme
    Create a new theme with the name of your skin and paste your skin's css and images into it.
  2. 2. Create a new master page
    Create a new master page and paste your skin's ascx control's entire markup over there. Replace all your content pane (i.e. div or tds with runat=server) with CotentPlace holder
  3. 3. Create a new page
    - Add a new aspx page called Default2.aspx and select the new master page when creating it. 
    - Go to .aspx.vb file and make your parial page class inherit from DotNetNuke.Framework.PageBase in place of System.Web.UI.Page 
    - And that's it you are ready to go!

Conclusion

It is really easy to add a new aspx page in dnn that is re-using skin and you will be able to access all the information like PortalSettings, UserInfo etc. Things like Tab and Module will not be there and it's obvious!
This post doesn't say you should create a new aspx page in some cases or not, but demonstrates how to do it if you want. If you have some good examples WHEN we can use it or some good examples WHEN we should NOT use it, I welcome them! 
This example will probably work with dnn 4.x and 5.x, though I've used this in dnn 4.5.6 and 5.2.0 etc.

Downloads

You can download the example code for this example from codeplex Happy coding with dnn

Saturday, December 4, 2010

DotNetNuke 5.6 - A potentially dangerous Request.Form value was detected from the client

Today morning, when I was preparing for a new installation instance for dnn 5.6, I was facing trouble to install new module, create new tab and I come to the conclusion that any post back event from the site was causing the "potentially dangerous Request.Form value".

I was still able to install module using /Install/Install.aspx?mode=installresource but finally stuck when I was not able to add the installed module into page.

Finally, after reading several articles on web, I found web.config's httpRuntime element needs another attribute called : requestValidationMode="2.0"

I go the solution here (
http://stackoverflow.com/questions/81991/a-potentially-dangerous-request-form-value-was-detected-from-the-client/3368769#3368769).

And finally, I was on my way to regular work.
please note that I was trying this on having webmatrix installed and I was browsing the site in asp.net 4.0 integrated mode.
Hope this will help to someone in the same kind of trouble.

Thursday, November 18, 2010

DNN Module development Using Nhibernate

Introduction
Hi All this is my first blog on Tricky Coders. In my last project which is in asp.net and I have used Nhibernate as the ORM which is very stable and also an open source project like DotNetNuke. So I decided to used it with DNN.
Prerequisites
Please download latest verion of NHibernate.
  1. Nhibernate.dll -This contains the NHibernate framework
  2. Iesi.Collections.dll -Iesi.Collections.dllContains the definition of some special collections used by NHibernate
  3. Castle.Core.dll-Base library is needed by Castle.DynamicProxy2.dll
  4. Castle.DynamicProxy2.dll - This contains code to generate proxies and is used by NHibernate to make e.g. lazy load possible
  5. We need to make some modifications in the web.config to support the Nhibernate.
Getting Started with Module Development
To create my module in DotNetNuke using Nhibernate i have used 2 projects
  1. DataAccessLayer- This class library project serves the purpose to connect with database by creating the object of Session Factory.
  2. Mapping Classes- This Class Library project serves the purpose of Defining the Entites and their mapping xml files.
  3. My Actual module which refer the above Projects to talk with data base.

Download 
    You can  download this module's source and installation package from tricky coder's codeplex project


    Please let me know about your views and suggestions to improve the code.

    Hope this will help.

    Thursday, November 4, 2010

    using WSO2 ESB to mediate WCF Service - Part 2

    In previous post, I demonstrated how to use Pass Through Proxy to mediate a basic WCF Service which is having GetData and GetCustomTypeData methods. In part 2, We will try to add UsernameToken security at WSO2 ESB level. 
    Pre-Requisites:

    Updating Service Implementation:
    Right now, I don't know how to use mediator to remove security header from soap envelop before sending it to the real service. I tried using Transformation > Header mediator but it didn't worked for me, so I used WCF Service side wrok around here. Please let me know how to do that, if some of you may know?
    • Open Service1.svc.vb and add following attribute to Service1 class:
    <servicebehavior(validatemustunderstand:=false)> _
    
    Securing wso2 esb service:
    • Login to esb website, and go to Services > List and click on WCFService
    • Click on Security
    • Select "Yes" for Enable Security and Select first option "UsernameToken"
    • Click on next and check the check box "Admin"
    • You will be redirected to service dashboard. 
    • That's it.
    Updating client to include security:
    • Install WSE 3.0 and add reference the wse 3.0 dll from it's installation directory to client project
    • Open Reference.vb from your client code, and change your web service class inherited from Inherits Microsoft.Web.Services3.WebServicesClientProtocol
    • Rebuild the client project again to make sure we haven't broken anything
    • Open Module1.vb and add following lines before calling GetData:
      Dim client As New localhost.WCFService
      Dim U As New UsernameToken( _
       "admin", _
       "admin", _
      PasswordOption.SendPlainText)
      client.RequestSoapContext.Security.Tokens.Add(U)
      ServicePointManager.CertificatePolicy = New TrustAllCertificatePolicy()
    Conclusion: 
    This way we can use wso2 esb to secure wcf service implemented using basicHttpBinding. Advantages here is, we are using separate GUI base server for securing wcf service which is too easy to maintain. 
    It is obvious that this example is very basic and it is just an exercise to add security in wcf services implemented using basicHttpBinding.

    Next steps will be to add some real life use cases that makes presence of esb more appropriate and not only for security.

    Pelase provide your thoughts on wso2 esb and wcf integration and if you are having trouble integrating with the same, you can drop me and email or post a comment here.

    using WSO2 ESB to mediate WCF Service

    In this post, I'm going to create a new WCFService with basicHTTPBinding and deploy it to IIS. I will mediate the deployed service with WSO2 ESB 3.0.0. For mediating the service, I will use "Pass Through Proxy".
    1. Pre-requisites
      1. Visual Studio 2008 or higher to create WCF Service
      2. wso2 esb 3.0.0 or higher, get it from here
    2. Install and Start  WSO2 ESB 3.0.0
      1. Extract the downloaded esb files
      2. Go to command prompt
      3. locate to bin directory of extracted esb
      4. write "wso2server.bat" and that will start the wso2 esb server after a few seconds
    3. Create a new WCF Service
      1. Start Visual Studio and go to File > New Project
        Create a new WCF Service Application from visual studio
      2. That will create a new WCF Service
      3. Open web.config and go to "system.serviceModel" element:

        <service name="xxx" behaviorConfiguration="xxxx">
            
            <!-- Service Endpoints -->
            <endpoint address="" binding="basicHttpBinding" contract="xxxx">    
            </endpoint>
            <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
           
        

        Make sure you change the endpoint element's binding attribute is having value basicHttpBinding
      4. Just Right click on the service project and click on Build Project
      5. It show you "Build Success" in status bar
      6. Right click on project again and click on publish
      7. Create a new folder called WCFServiceDeployed and select it as output directory
      8. Go to IIS and Create a new virual directory called "WCFService" and point it to WCFServiceDeployed folder
      9. right click on Service1.svc (or whatever svc file you have) and click on browse.
      10. Copy the wsdl url shown in the service page.
    4. Create Pass through proxy in wso2 esb
      1. Make sure you have wso2 esb up and running
      2. Locate your browser to https://localhost:9443/carbon
      3. use admin/admin as username/password to login to the site
      4. Click on Services > Add > Proxy Services
      5. Click on "Pass Through Service"
      6. enter "WCFService" in "Proxy Service Name" text box
      7. In "Target Url" add url of WCF Service
      8. Expand "Publish WSDL" option
      9. From the Publish WSDL drop down menu, choose "Specify Source Url"
      10. In the text box of WSDL URI, enter your published svc url suffixed with ?wsdl
      11. Expand Transport
      12. Uncheck HTTPS transport
      13. Click on create
      14. Go to Services > List
      15. Click on WCFService
      16. Copy the endpoint url
    5.  Creating Client for the newly created service in esb
      1. Start Visual studio
      2. Create a new console application project (i'm using visual basic)
      3. Right click on the project and click on add web reference
      4. enter the url of the endpoint that you get from web esb
      5. click on ok
      6. go to module1.vb
      7. Add following code:
        Dim client As New localhost.WCFService
        Dim strData As String = client.GetData(100, True)
        Console.WriteLine(strData)
        
        Dim cmpType As New localhost.CompositeType
        cmpType.BoolValue = True
        cmpType.BoolValueSpecified = True
        cmpType.StringValue = "It works" 
        Dim retCmpType As localhost.CompositeType = client.GetDataUsingDataContract(cmpType) 
        Console.WriteLine(retCmpType.StringValue)
        Console.ReadKey()
        
    That's It, you will see the output in console window. Press any key to exit the console application.
    Please note that I'm using web reference because I am not able to correcly implement WCF Client  for the service yet. In upcoming post, I will cover how to secure WCF service with basicHTTPBinding with wso2esb

    Tuesday, November 2, 2010

    Building Java Web Services with Axis2 and Eclipse

    I was working on middle-ware integration with wso2 and axis2 web services since last couple of months. In this post, I will show how to get started with axis2 development and deployment using Eclipse IDE.
    1. If you are not having an Eclipse IDE, I am using helios
    2. If you are already having Eclipse IDE. make sure you have WTP Plugin installed.
    3. Create a new workspace in eclipse
    4. Download and install any version of apache tomcat (I'm using tomcat 5.5). If you are having troubles configuring it on your machine, you can locate to apache tomcat help for installation here
    5. Add apache tomcat server to your Eclipse IDE, and here is how you can do it.
    6. Get Axis2
      Download latest source of Axis2 from here
    7. See Anil John's this article for properly configuring axis2 and related environment variables.
    8. Once you are done with step 7, you can start integrating axis2 with Eclipse IDE by using this article at eclipse WTP Tutorials.
    9. For deploying axis2 plugin using .aar package, donwload Apache Axis2 Archive plugin
    10. Extract the zip file of Apache Axis2 Archive plugin and copy the folder having plugin.xml and paste it to plugins folder of your eclipse installation root directory
    11. You are done with the configuration and ready to create a new web service. See this tutorial on eclipse WTP tutorials to create a new axis2 service.
    I am a .net developer, and successfully created and deployed the services created using Eclipse IDE to wso2 wsas.I have done this using windows xp, apache tomcat 5.5, axis2 1.5 and wso2 wsas 3.0.0. I hope this post will be helpful to you and will save your time to get started with axis2 development.
    I will try to share my experience of working with wso2 wsas and wso2 esb with you in upcoming posts.

    Monday, November 1, 2010

    Unable to engage module rampart

    If you have ever tried to create an axis web service with security, you probably have see this error:
    AxisFault: unable to engage module "rampart" 
    When I encountered this problem, I was working with eclipse having axis2 plug-ins. I found a solution in WSAS Forum.

    Wonderful thing to note is, I got this error fixed and while reading the forums of wso2 wsas, I got this link and I thought it would be good to share this.

    Note: This post is applicable to those who are not using axis2 repositories for development and using standalone eclipse projects. I was using the same.

    Popular Posts