Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I have a static web site with a blog (an asp.net application), the blog is in a subdirectory of the web site so:

example.com/, example.com/Something.htm, example.com/folder/somefile.htm, etc. - are all static files

example.com/blog, example.com/blog/categories.aspx, example.com/blog/2011/11/09/post-name.aspx, etc. - all go to the blog app

I'm upgrading the static part of the web site to a dynamic site (also an asp.net application) and the blog is incompatible with the new app (the app needs handlers and modules loaded in web.config that don't work with the blog)

Also, I have to keep all the old URLs the same - so I can't move the blog to a subdomain or the new app to a folder and the blog generates links based on its folder so clever redirection tricks wouldn't work.

Is there a way to place an asp.net application in a folder inside another application (either as a real or virtual folder) so that the root web.config settings don't apply to the application folder? Or some other trick I didn't think of?

The system is running IIS7 on Windows Server 2008 64bit, I have full control over the server's configuration.

I can't modify the blog's source code but I can edit its web.config and other configuration.

I can modify the source of the new application but I can't make it compatible with the blog (most of its usefulness comes from a 3rd party library that is not compatible with the blog).

The blog in an asp.net 3.5 webforms application

The new root application is an asp.net 4.0 mvc application

share|improve this question

3 Answers 3

up vote 2 down vote accepted
+100

You can edit the blog software's web.config file, either manually or via the "Internet Information Services (IIS) Manager" tool to disable various modules and handlers as required. For example, to remove one handler and one module that are installed and available by default in IIS 7.5:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <modules>
            <remove name="Session" />
        </modules>
        <handlers>
            <remove name="StaticFile" />
        </handlers>
    </system.webServer>
</configuration>

You should be able to just "drop-in" the names of the problem modules and handlers and the blog software will start working again.

The steps to do this via IIS Manager would be:

  1. Open IIS Manager and connect to the machine you wish to configure
  2. In the treeview to the left, navigate down to the application that you want to configure
  3. Choose "Handler Mappings" or "Modules" in the main pane
  4. Click on each handler or module you wish to remove and either hit [DEL], use the "Remove" link under actions or right-click and choose "Remove" from the context menu.
share|improve this answer
1  
This works, just for future reference I had to add <remove> elements for everything added in the root web.config under system.webServer/modules, system.webServer/handlers, system.web/compilation/assemblies, system.web/pages/namespaces and also remove the targetFramework attribute in system.web/compilation –  Nir Nov 20 '11 at 8:16
    
@Nir - The "targetFramework" attribute, where was that? It shouldn't be present in the web.config for the /blog/ application unless said application was upgraded to .net4 at some point as it wasn't introduced into the configuration schema until then =) –  Rob Nov 24 '11 at 9:36
    
it wasn't in the blog, it was in the root application and the blog crushed with an invalid configuration schema error because the blog is .net3.5 –  Nir Nov 24 '11 at 22:16

You can create new application for that specific folder under its Properties window, Home Directory (or Virtual Directory for virtually created directories) tab. I guess you want home directory for updated new .net content. After you configure web site for it go to blog folder and create an application for it. Then go to ASP.NET tab and correct the app version because when you configure parent web site for v4.0, blog's version will change to that, too. You should change it back to v3.5

Being mentioned of, every application will have its own web.config file so two different application won't cross each other..

share|improve this answer
    
It doesn't work, the blog is already an application and IIS processes both its web.config and the root web.config for it - also, your instructions apply to IIS 6 not 7 –  Nir Nov 19 '11 at 9:13

I don't think it is possible while the directories are physically nested. Probably the easiest way is to use the IIS tools URL rewrite or Application Request Routing.

Using the ASP routing stuff will probably not work since the app needs to be in it's own domain.

If you really want to avoid using the IIS stuff, you could let your new MVC application work as a proxy and call the other application from the Blog control and return the result. You will then also have to take into account for when your blog app generates links with url's using code like this:

ResolveUrl("~/...")

You'll need to search and replace those URLS (untested, you'll need to tweak some stuff here to get it working, but the basic idea can be extracted):

public class BlogController : Controller {
  protected override void HandleUnknownAction(string actionName) {
    string newUrl = ConvertToNewUrl(Request.Url);
    System.Net.HttpWebRequest newRequest = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(newUrl);
    System.Net.HttpWebResponse newResponse = (System.Net.HttpWebResponse)newRequest.GetResponse();

    System.IO.Stream resStream = newResponse.GetResponseStream();
    byte[] content = new byte[resStream.Length];
    resStream.Read(content, 0, (int)resStream.Length);

    if (newResponse.ContentType == "text/html") {
      System.IO.MemoryStream ms = new System.IO.MemoryStream(content);
      using (System.IO.StreamReader sr = new System.IO.StreamReader(ms)) {
        string strContent = sr.ReadToEnd();

        strContent = strContent.Replace("example.com/something", "example.com/blog");
        using (ms = new System.IO.MemoryStream()) {
          using (System.IO.StreamWriter sw = new System.IO.StreamWriter(ms)) {
            sw.Write(strContent);
            content = ms.ToArray();
          }
        }
      }
    }

    Response.Write(content);
  }
}

but I must admit that that's the most fishy solution I can think of :-) I recommend you to first give URL rewrite or Application Request Routing a shot.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.