Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4093324
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T19:36:14+00:00 2026-05-20T19:36:14+00:00

I have some code to create a Virtual Directory programmatically. I need to edit

  • 0

I have some code to create a Virtual Directory programmatically.

I need to edit handler mappings of framework 2.0 to use .net 4.0 (basically run .net 2.0 code under .net 4.0 CLR).

The code below works fine under win 2003 server, but on Windows 2008 server webservicefactoryHandler2.0 is renamed as webservicefactoryHandler4.032_1245.

I don’t know how to access/edit this name or infact retain the name and just change its value to \Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll from \Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll.

Dim scriptMapVals As PropertyValueCollection = VDir.Properties("ScriptMaps")
Dim objScriptMaps As ArrayList = New ArrayList()
Dim frameworkVersion As String = "4.0.30319"
Dim versionRegex As Text.RegularExpressions.Regex = New Text.RegularExpressions.Regex("(?<=\\v)\d{1}\.\d{1}\.\d{1,5}(?=\\)")
''Assuming the version will always be something like n.n.nnnnn

Dim scriptMapVal As String
For Each scriptMapVal In scriptMapVals
  If scriptMapVal.Contains("Framework") AndAlso scriptMapVal.Contains("asmx") Then
      objScriptMaps.Add(Text.RegularExpressions.Regex.Replace(scriptMapVal, versionRegex.ToString, frameworkVersion))
  Else
      objScriptMaps.Add(scriptMapVal)
  End If
Next

VDir.Properties("ScriptMaps").Value = objScriptMaps.ToArray()
VDir.CommitChanges()

Update:
@kev : So basically you are saying to use different code for different version of IIS right? Well while using import “Microsoft.Web.Administration.dll” , do i need to pack it up in my build ? or this is part of all IIS7.0 installables? as Some poeple could have IIS7.0 on Windows XP.

Thanks
gauls

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T19:36:15+00:00Added an answer on May 20, 2026 at 7:36 pm

    First of all, don’t use the IIS6 compatibility API to manipulate IIS7 handler mappings. Use the Microsoft.Web.Administration managed API instead.

    However, you’re going about this in completely the wrong way. You shouldn’t be touching the handler mappings but instead change the managed runtime version for the application pool in in which the application resides.

    Add a reference to:

    C:\Windows\System32\inetsrv\Microsoft.Web.Administration.dll

    Then in your code:

    using Microsoft.Web.Administration;    
    ...
    
    using (ServerManager serverManager = new ServerManager())
    {
      ApplicationPool appPool = 
          serverManager.ApplicationPools.Where(a => a.Name.Equals(appPoolName))
          .Single();
      appPool.ManagedRuntimeVersion = "v2.0";
      serverManager.CommitChanges();
    }
    

    I would also recommend NOT using the ADSI compatibility API’s at all to manipulate IIS7’s configuration. Learn to love and embrace <applicationHost> and forget about thinking in terms of metabase objects in IIS7:

    http://www.iis.net/ConfigReference/system.applicationHost

    Update:

    Further to your question about having code that works with both IIS6 and IIS7 I would thoroughly recommend NOT using the IIS6 compatibility layer for the convenience of having to maintain just one codebase.

    The reason for this is that features of IIS7 objects such as HandlerMappings (the equivalent of Script Mappings) are handled differently. The compatibility shim creates what’s known as ABO Custom Map objects which lose some of the benefits of proper HandlerMappings. Whilst they work they will create an administrative nightmare in the longer term. Trust me, I’ve been there.

    If you need to detect which version of IIS your running then here is a handy function to do that:

    public static int GetIIsMajorVersion()
    {
      string regKey = @"SOFTWARE\Microsoft\InetStp";
      using(RegistryKey key = Registry.LocalMachine.OpenSubKey(regKey, true))
      {
        return Convert.ToInt32(key.GetValue("MajorVersion"));
      }
    }
    

    If the return value is 6 then it’s IIS6, if it’s 7 then you’re on IIS 7.x.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

we have some C++ code that we need to create a make file in.
I have some vbscript code I use to set paths to virtual directories when
I have some code to create a basic dialog box with several options -
I have been writing some code to create a byte array I will be
Suppose I have the following: using(var ctx = DataContextFactory.Create(0)) { ... Some code ...
I need to create a virtual file, a file that if some program access
I have some POCO objects that are set up for use with Entity Framework
I have some code that creates some span tags and each span has its
I have some code that creates a Process instance and later starts it. There's
I have some code that creates a bunch of UITextViews and puts them into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.