同一目录下,不同子目录中,多网站程序,多bin目录,多webconfig 解决方案

Apparently there's a number of places online that say this can't be done. We needed to be able to add pages to an existing application that were basically "sub-applications," and they'd have their own /bin folder, but still be in the same VDIR and participate in the same IIS Application.

So instead of:

/webapp
 default.aspx
 foo1.aspx
     /bin
      app.dll
      foo1.dll

We could have

/webapp
 default.aspx
     /bin
     /mysubapp
      foo1.aspx
          /bin
           foo1.dll

If you try this directory layout as is, you'll get a "Parser Error" as ASP.NET freaks out due to its inability to find the code-behind for foo1.aspx.

However, if you add a private probingPath to your web.config:

<configuration>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <probing privatePath="mysubapp/bin" /> <%-- 根目录下的相对路径 --%>
    </assemblyBinding>
  </runtime>
<configuration>

 

And, tell your ASPX page where it can find it's code-behind file BEFORE the System needs it for the Inherits= attribute in the @Page directive:

<%@ Assembly Name="Foo1" %>  <%-- Foo1:引用程序集 --%>
<%@ Import Namespace="FooNamespace" %>  <%-- FooNamespace:引用程序集Foo1 下的FooNamespace命名空间 --%>
<%@ Page language="c#" Trace="true" Codebehind="Foo1.aspx.cs" AutoEventWireup="false" Inherits="FooNamespace.FooWebForm1" Debug="true"%>

You'll be all set. Slick. Of course, this is all ASP.NET 1.1, and everything changes with 2.0 and the "/Code" directory, but it's still slick IMHO, and allows for a level of flexibility that I haven't seen before.  It also keeps your man/bin nice and tidy if you've got folks "plugging in" other pages to your web app.

posted @ 2010-09-28 12:27  caicainiao  阅读(228)  评论(0)    收藏  举报