首先声明,本文所述内容只做了简单的测试,也就是说不保证在任何情况下都适用,因此仅供需要整合的朋友们参考。遇到问题还是要多Google一下。
言归正传,有几个问题需要先说明
1 我的asp.net 程序到底读哪个web.config文件a. 在IIS6的模型下,如果在站点myweb 下建立了 bbs虚拟目录,并且为bbs建立的应用程序池,那么bbs下运行的asp.net程序会读取bbs目录下的 web.config.如果此时 bbs目录下没有web.config文件,那么程序将检测站点根目录myweb是否存在web.config文件,如果存在则使用其配 置,如果不存在就报错啦。
b. 如果bbs不是虚拟目录,或者虽然是虚拟目录但是没有应用程序池,那么程序将读取网站根目录下的web.config文件。2 如何设置web.configa. bbs目录没有应用程序池,bbs程序和网站根目录下的程序使用同一个web.config的情况(适合多数虚拟主机用户)
web.config文件中可以同时存在多个<system.web>配置节,但是要指明<location path="bbs" allowOverride="false">
请看下面的web.config文件实例
<?xml version="1.0" encoding="gb2312"?>
<configuration>
<configSections>
<section name="RewriterConfig" type="URLRewriter.Config.RewriterConfigSerializerSectionHandler, URLRewriter" />
</configSections>
<RewriterConfig>
<Rules>
<RewriterRule>
<LookFor>~/c(\d{1,8})\.aspx</LookFor>
<SendTo>~/list.aspx?cid=$1</SendTo>
</RewriterRule>
<RewriterRule>
<LookFor>~/c(\d{1,8})p(\d{1,6})\.aspx</LookFor>
<SendTo>~/list.aspx?cid=$1&page=$2</SendTo>
</RewriterRule>
<RewriterRule>
<LookFor>~/n(\d{1,8})c(\d{1,8})\.aspx</LookFor>
<SendTo>~/show.aspx?id=$1&cid=$2</SendTo>
</RewriterRule>
<RewriterRule>
<LookFor>~/n(\d{1,8})c(\d{1,8})p(\d{1,8})\.aspx</LookFor>
<SendTo>~/show.aspx?id=$1&cid=$2&page=$3</SendTo>
</RewriterRule>
</Rules>
</RewriterConfig>
<appSettings>
<add key="Charset" value="gb2312" />
<add key="NewsUrl" value="http://localhost:91/" />
<add key="GroupId" value="1" />
<add key="IwmsCode" value="832a93be4a31650e282c05a3a6453121" />
</appSettings>
<system.web>
<compilation defaultLanguage="C#" debug="true"/>
<!--如果为.net SDK 1.0及以前版本,请删除validateRequest="false" -->
<pages validateRequest="false" enableSessionState="true" enableViewState="true"/>
<customErrors mode="Off" />
<globalization fileEncoding="gb2312" requestEncoding="gb2312" responseEncoding="gb2312" culture="zh-CN" />
<httpRuntime maxRequestLength="2048" />
<httpModules>
<add type="Discuz.Forum.HttpModule, Discuz.Forum" name="HttpModule" />
<add type="URLRewriter.ModuleRewriter, URLRewriter" name="ModuleRewriter" />
</httpModules>
<httpHandlers>
<add verb="*" path="*.aspx" type="URLRewriter.RewriterFactoryHandler, URLRewriter" />
<add verb="POST,GET" path="ajaxpro/*.ashx" type="AjaxPro.AjaxHandlerFactory, AjaxPro"/>
</httpHandlers>
</system.web>
<location path="bbs" allowOverride="false">
<system.web>
<globalization
requestEncoding="utf-8"
responseEncoding="utf-8"
fileEncoding="utf-8"
/>
<httpModules>
<add type="Discuz.Forum.HttpModule, Discuz.Forum" name="HttpModule" />
<remove name="ModuleRewriter" />
</httpModules>
</system.web>
</location>
</configuration>
注意其中 用<location path="bbs" allowOverride="false"> 指名了作用的对象是bbs目录,而且不允许重写。
<remove name="ModuleRewriter" /> 这行 从应用程序移除 ModuleRewriter 类,也就是让网站根目录程序的ModuleRewriter对bbs目录不起作用。
修改好了web.config文件 还需要把多有的bbs目录下Discuz!NT Bin目录下的dll文件都复制到根目录的Bin目录下。
关于这个问题 请参考宝玉哥哥的文
http://blog.joycode.com/dotey/archive/2004/11/30/40010.aspxb. bbs是虚拟目录且有应用程序池的情况 还没有来的急测试,但使用<remove name="ModuleRewriter" /> 是一定要的
希望有兴趣的朋友测试一下。
本文到此结束,文中如果有错误或者大家有自己的想法 非常欢迎大家提出来,一起研究。
另外提醒大家看我的签名