解决方案:.net 4.0 下 Virtual Directory下如何部署一个作为Virtual Directory的Web Service

情景

最近项目里有个需求,本生我们有个项目叫做A,然后部署到windows2003 server的IIS下的default web site 下的叫A的Virtual Directory。最近要加一个独立于这个项目A的webservice B,也就是说B的Release时间可以和A不同步。不知道为啥,老美希望在A这个VD下建一个子的VD C,然后这个C里面部署webserivce B,也就是说这个C就是一个嵌套的VD。C里面有一个webconfig,一个asmx,一个bin下面有dll

问题

用IE直接测试这个Webservice,打开asmx文件,会报parse error, can not create type ***,这个asmx里面只有一些标记语言,没有C#代码,从错误来看是没有搜索到这个bin,如果我们把asmx.cs文件里面的代码直接拷贝到asmx的文件里面,在打开这个asmx就没问题。

其实情景和问题类似于:http://www.haogongju.net/art/1001932,但我按照里面的解决方案并没有解决问题。

解决方案

花了一天半时间终于解决了这个问题,目前找到3个解决方案

1。就是上面提到的拷贝C#代码到asmx中

2。A里面有个webconfig文件,里面assemblies节点下的所有非gac的dll都要拷贝到C的bin中,C的webconfig assemblies节点不需要<clear/>

3。C的webconfig节点<remove>掉A里面非gac的dll,这样就不要像2中那样拷贝dll了。

参考

http://runtingsproper.blogspot.com.au/2010/04/solved-breaking-parent-webconfig.html

The reason this is occurring is actually by design. The settings inside the main web.config will cascade downwards and all other config files will inherit the settings. If they have settings of their own they will override the parent. In fact even the root web.config is being merged with a server wide file called machine.config.

So what's happening is the references to the assemblies in your main \bin\ folder are being passed down to the sub application and when it looks in its own bin folder it finds they aren't their and throws an error.

但是用inheritInChildApplications我试出来并不对

http://weblogs.asp.net/jgalloway/archive/2012/01/17/10-things-asp-net-developers-should-know-about-web-config-inheritance-and-overrides.aspx

http://forums.asp.net/t/1164283.aspx/1

http://msdn.microsoft.com/zh-cn/library/ms178685%28v=vs.80%29.aspx

如果你的这个C的验证方式authentication不希望依附于A那么你可以在C中的webconfig里添加

<location path=".">
  <system.web>
   <authorization>
    <allow users="*"/>
   </authorization>
  </system.web>
 </location>

这样你就可以直接访问C了,而不需要先登入A。

注意:我这里说明的都是.net4.0下的情况,1.1和2.0有所不同

 

posted @ 2012-07-04 14:16  nickycookie  阅读(1125)  评论(1编辑  收藏  举报