Nik's Technology Blog

Travels through programming, networks, and computers

Ambiguous DLLs

We’ve just been testing an upgrade our CMS and come across a few problems concerning newer versions of assemblies interfering with older versions stored in the GAC.

The solution is to use a binding redirect in Web.Config to tell the framework to use the latest version.  For more info see Redirecting Assembly Versions.

   1: <runtime>
   2:   <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
   3:     <dependentAssembly>
   4:       <assemblyIdentity name="Immediacy.Web" publicKeyToken="b35b2a186fcebe46"/>
   5:       <bindingRedirect oldVersion="6.1.0.0" newVersion="6.2.0.0"/>
   6:     </dependentAssembly>
   7:   </assemblyBinding>
   8: </runtime>

To get the publicKeyToken for the DLL you need to open a Visual Studio command prompt and navigate to the folder containing the DLL and type:

SN –T assemblyname.dll

This will give you the publicKeyToken to put in the assembly identity.

Alternatively you could remove the old version of the DLL from the GAC by using this command with the Global Assembly Cache Tool

gacutil /u Immediacy.Web, Version=6.1.0.0, Culture="en",PublicKeyToken=b35b2a186fcebe46

Developing Scheduled Tasks for Immediacy Management Console (Alterian CMC)

Immediacy Management Console Scheduled Tasks are useful for running tasks that need to occur automatically on a frequent basis which are independent of website visitor actions.

immediacy-mc

These scheduled tasks have the advantage of being able to hook up to the Immediacy API, allowing developers to perform tasks on Immediacy pages etc.

Scheduled tasks can have public properties if required, which are entered via a Plug-in Settings dialog box.

immediacy-mc-settings

Plug-in Development

Immediacy Management Console plug-ins are simply a .NET class library. The project should contain a C# or VB.NET file containing the plug-in and a separate class which defines the Plug-in Settings dialog.

The plug-in class needs to reference the following Immediacy namespaces.

Immediacy.Configuration;
Immediacy.Service.Interfaces;

Your plug-in class needs to inherit from:

Immediacy.Service.Interfaces.Plugin

And your class needs to have a few class attributes for Immediacy (CMC) to recognise your plug-in:

    [SettingsControlTypeAttribute(typeof(SiteMapSettings))]
    [GuidAttribute("XXXX8D90-XXXX-XXXX-XXXX-A3341127XXXX")]
    [PluginDetailsType("Name of Plug-in", "Description")]

Your plug-in class constructor needs to pass the settings to the base class as follows:

public Sitemap(ImcFile imcFile, StringDictionary settings) : base(imcFile, settings) { }

To build your plug-in you need to override the Execute() method and put your code in here.

Plug-in Settings Dialog Development


The plug-in settings dialog is created by another class, which inherits from Immediacy.Service.Interfaces.SettingsControl

This class is essentially a Windows Form code file without the form designer, so you’ll need to import the  System.Windows.Forms namespace.

You’ll need to add Windows.Forms Labels and TextBoxes to the dialog box to capture the public properties from the user who configures the plug-in while scheduling it.

Implement the abstract class like the example below:

 

namespace ImmPlugins.Sitemap

{

    public class SettingTest : Immediacy.Service.Interfaces.SettingsControl

    {

        private System.Windows.Forms.TextBox txtUrl;

  private System.Windows.Forms.Label lblUrl;

 

  private System.ComponentModel.Container components = null;

 

        public SiteMapSettings(Type pluginType)

            : base(pluginType)

        {

            InitializeComponent();

        }

 

        public override System.Collections.Specialized.StringDictionary Settings

        {

            get

            {

                StringDictionary retVal = new StringDictionary();

                retVal.Add("url", txtUrl.Text);

                return retVal;

            }

            set

            {

                txtUrl.Text = (string)value["url"];

            }       

  }

 

        public override bool SettingsAreValid

        {

            get {

                  if (txtUrl.Text == “”)

                  {

return false;

                  }

                  else

                  {

                        return true;

                  }

}

        }

 

        public override string SettingsAreValidVerbose

        {

            get {

string errorText = string.Empty;

                  if (txtUrl.Text == "")

                  {

errorText += "Please specify a URL \r\n";                 

}

return errorText;
}

        }

 

        private void InitializeComponent()

        {

            this.lblUrl = new System.Windows.Forms.Label();

            this.txtUrl = new System.Windows.Forms.TextBox();

 

            this.txtUrl.Location = new System.Drawing.Point(202, 59);

            this.txtUrl.Name = "txtUrl";

            this.txtUrl.Size = new System.Drawing.Size(160, 20);

            this.txtUrl.TabIndex = 2;

 

            this.lblUrl.Location = new System.Drawing.Point(8, 59);

            this.lblUrl.Name = "lblUrl";

            this.lblUrl.Size = new System.Drawing.Size(188, 16);

            this.lblUrl.TabIndex = 1;

            this.lblUrl.Text = "URL:";

 

this.ClientSize = new System.Drawing.Size(374, 183);

            this.Controls.Add(this.lblUrl);

            this.Controls.Add(this.txtUrl);

            this.Name = "PluginSettings";

            this.ResumeLayout(false);

            this.PerformLayout();

        }

 

        protected override void Dispose(bool disposing)

        {

            if (disposing)

            {

                if (components != null)

                {

                    components.Dispose();

                }

            }

            base.Dispose(disposing);

        }

    }

}

Plug-in Installation


Immediacy Management Console plug-ins are installed in the Immediacy CMS folder path.

Simply compile your .NET class library to a DLL and copy it to this directory.

e.g. C:\Program Files\Immediacy\CMS\6.1\Service\Plugins

(Note: This path maybe slightly different on your installation depending on Immediacy version, drive path etc)

If all has gone well your plug-in should show up in the list of tasks which can be scheduled in the Immediacy Management Console.

Configuring FTP for Windows Server 2008

Setting up FTP on Windows Server 2008 isn’t as easy as in previous versions and the steps you need to take vary depending on what version of IIS you have installed.

Unless you upgrade to IIS 7.5, FTP in IIS 7 is still managed with IIS 6 Manager!

FTP configuration in IIS 7

Failed to Retrieve Directory Listing

The first hurdle I encountered when trying to connect using Filezilla was the error message “Failed to Retrieve Directory Listing”.  Filezilla was able to connect but couldn’t list the files in the remote folder.

A work around to this is to run Filezilla in active mode (Edit > Settings > Connection > FTP > Active), but some programs that use FTP such as Windows Live Writer can’t be set to use active and prefer passive FTP.  Read more about active and passive FTP.

Configuring Passive FTP on IIS

Configuring Passive FTP on IIS essentially involves configuring FTP port ranges in IIS for the passive connection and then opening up those ports in Windows Firewall on the server.

Depending on what version of IIS you have installed I can verify that both of these methods work.  Although the c:\Inetpub\adminiscripts folder didn’t exist on my server so I ended up getting them from a Windows Server 2003 machine.

My advice would be to upgrade to IIS 7.5.

Apache Web Development Testing Server Set-up

I've been setting up an Ubuntu linux machine for web development testing on my local network, but because the machine has only one IP address assigned to it I wanted a solution to be able to serve more than one website without changing the config in Apache each time.

One method would be to use a separate folder for each site but .htaccess rewrites don't work properly using this method and if you write hyperlinks that refer to the root of the site (i.e /contact.php), this can cause issues too.

Anyway, I thought of using different port numbers to distinguish the different testing websites. So one site maybe on 192.168.0.1:2000, another on 192.168.0.1:2001 etc...

You set this up in Ubuntu as follows:

Open a Terminal prompt and type:

sudo gedit /etc/apache2/ports.conf

Enter your password and then for each port number you require add a Listen statement on a new line. So your file should look like:

Listen 80
Listen 2000
Listen 2001

<ifmodule>
Listen 443
</ifmodule>

Save the file and then go back to the Terminal and type:

sudo gedit /etc/apache2/sites-available/default

In this file you should find a <virtualhost *> tag followed by various commands. You need to copy and paste everything from <virtualhost *> to </virtualhost> onto a new line below.
Then rename the first <virtualhost *> to <virtualhost 192.168.0.1:80> where 192.168.0.1 is the IP address of you machine. Rename the second virtual host to <virtualhost 192.168.0.1:2000> and repeat for as many websites you want to set-up.

Then for each Virtual Host you'll need to change the DocumentRoot to the file path to each website on the local machine.

Once this is done you'll need to restart Apache to see if your changes have been successful. To do this type the following into the Terminal:

sudo /etc/init.d/apache2 restart

Product Review: Train Signal's IIS Web Servers CBT Video Training

As an ASP.NET web developer, I think it's important to understand and know how to configure Microsoft's web server, Internet Information Services (IIS). Depending on the organisation you work for you may or may not get the opportunity to tinker with IIS, but this shouldn't stop you from learning the basics.

You could go out and buy a book on configuring IIS and then install IIS on your computer to practise what you've read, but thanks to the guys at Trainsignal.com who have kindly sent me some of their training videos, I've discovered a much easier way of learning.

Train Signal CD-ROM

Train Signal provides video training courses for Microsoft, Cisco and CompTIA certifications, including CCNA, A+, Network+.
I'll also be reviewing the Cisco CCNA training videos here soon.

Train Signal's IIS Web Server video training covers both IIS 5 and IIS6, and features topics including installing IIS, creating test websites, hosting more than one website using host headers, adding security, setting up an FTP server, and web server optimisation.

Train Signal CD-ROM menu

The course is taught by Scott Skinger, President and founder of Train Signal. Scott has many years of experience in the IT field, holds various IT certifications and is a competent instructor. The videos are easy to follow and Scott's narration is second to none.

Train Signal lab book sample

The series of videos are backed up with a written guide in the form of the lab book, which comes as a printable PDF on the CD ROM, this goes through the same steps featured in the videos and includes network diagrams like the one above to help you set-up your own lab.

Train Signal video player

If you want to get up to speed on a particular Microsoft product, obtain an IT certification or you don't like reading IT text books then I definitely recommend you give these training videos a try.

Course Contents in full:

Introduction
Lab Setup
Setting up the lab
Computer 1
Computer 2
Computer 3
Lab
Scenario
Installing IIS on Windows 2000 Server
Creating an HTML file
Hosting Ben & Brady's site
Configure DNS so Internet users can find your website
Testing the website from the client
Lab
Scenario
Creating a test website using an HTML file
Creating an additional website on the web server
Creating host headers
Configuring DNS for the second website
Test and view website from client
Assigning site operators
Adding security to a website
Test and view the website from a client
Lab
Scenario
Downloading and installing service packs and hot fixes
Setting NTFS permissions
Disabling Netbios over TCP/IP
Download and run The IIS lockdown tool from Microsoft
Enable and view logging

IIS 7 and Configuration Delegation on Shared Servers

I've just been watching the IIS 7.0 episode of the .NET Show. One of the new exciting features of IIS 7.0 for people who run their sites on a shared hosting environment are the new Delegated, Remote Administration options.

Essentially this will allow developers who do not have access to IIS on the box to use an IIS client tool to configure their site remotely over HTTP. This obviously relies on the hosting company to offer this functionality.

This has been a major bugbear for developers running their sites on IIS in the past in a shared environment. If set-up correctly it should allow hosting companies to save time and money by delegating some IIS functionality out to the site administrators.

I've recently moved hosting companies in order to get ASP.NET and the .Net framework 2.0, and I think that it will be big selling point for hosting firms. As far as I'm aware you will need Vista or Longhorn server to get IIS 7.0 however, so we may not see hosting companies offering this for a while yet.

404 Error pages Returns code 200

Since a site redesign we've been using a custom 404 ASP page rather than our old HTML 404 page, this gives us the opportunity to add dynamic content to the 404.asp page.

However after setting up Microsoft IIS to serve our custom 404.asp page we discovered to our dismay, using a HTTP header viewer, that the 404 page was returning a code '200 OK' rather than a '404 Not Found'.

After some searching the ASP Response.Status object was found. Now with just one line of code at the top of our ASP 404 page we can set the status to 404 Not Found!

Here's the code.

<%

Response.Status = "404 Not Found"

%>

I've added a link to a handy HTTP viewer below.

http://www.rexswain.com/httpview.html