views:

40

answers:

2

I have installer that will create virtual directory.

It works fine on IIS 6.

But if I try on IIS 7.5 it crashes.

Then i tried using Microsoft.Web.Administration class

But now it will work only on IIS 7 and IIS 7.5

Can anyone help me out so that my code works for both IIS 6 and IIS 7.5?

A: 

If you want to use the same code to create websites on both IIS6 and IIS7 (which I suspect is using the System.DirectoryServices namespace) then you need to install the IIS6 Management Compatibility features. You can do this by adding this as a Role Service to the Web Server role in Server Manager (under Administrative Tools).

Alternatively you can use the command line on Windows 2008 and Windows 2008R2 (run as Administrator):

Windows 2008/2008R2 -

servermanagercmd -i Web-Mgt-Compat -a

Windows 2008R2 -

ServerManagerCmd.exe is deprecated and you are advised to use the ServerManager PowerShell module:

import-module ServerManager
add-windowsfeature Web-Mgt-Compat -includeallsubfeature
Kev
Thanxs for reply..But I want the code in C# language...Also I cant enable IIS6 compatible mode on server as I dont have rights
Sunil Agarwal
@Sunil - unfortunately in this case you're going to have to maintain one codebase for IIS6 (System.DirectoryServices) and one for IIS7 (Microsoft.Web.Administration).
Kev
A: 

Finally I have created 2 separate classes for managing IIS6 and IIS7.5.

And its working fine.

Sunil Agarwal
@sunil - so for my time and assistance do not I get an upvote? :)
Kev