一、在應用程序級別之外使用註冊爲 allowDefinition='MachineToApplication' 的節是錯誤的
原因:如果在 IIS 中沒有將虛擬目錄配置爲應用程序,則可能導致此錯誤。
1、若IIS中沒有應用程序名,先創建,若還不行把C:\WINDOWS\Microsoft.NET\work\v2.0.50727\CONFIG\machine.config中的所有allowDefinition="MachineToApplication"改爲allowDefinition="Everywhere";
二、整個網站要放在根目錄下;
三、一個項目中帶有兩個Web.config而產生了上述錯誤。將包含另一個Web.config的文件夾刪除掉之後問題消失
這裏可能還有其他問題引發的
在ASP.NET2.0中,如果根目錄允許匿名用戶訪問,而根目錄下的一個頁面(如Index.aspx)必須要登錄(假設登錄頁面爲login.aspx)後才能訪問,根目錄下的web.config文件必須這樣配置:
<?xml version="1.0"?>
<configuration>
<appSettings>
</appSettings>
<connectionStrings>
</connectionStrings>
<system.web>
<compilation debug="true"/>
<!--<authentication mode="Windows"/>-->
<authentication mode="Forms">
<forms loginUrl="login.aspx" protection="All" path="/" timeout="30"/>
</authentication>
<authorization>
<!--允許匿名-->
<allow users="?"/>
</authorization>
</system.web>
<location path="Info.aspx">
<system.web>
<!--認證項配置(在爲一個單獨頁面指定認證信息時,authentication節只能從這個目錄繼承,不能單獨設置)-->
<!--
<authentication mode="Forms">
<forms name=".www.cnpp.info" loginUrl="login.aspx" protection="All" path="/" timeout="30"/>
</authentication>
-->
<!--用戶訪問控制-->
<authorization>
<!--阻止匿名-->
<deny users="?"/>
</authorization>
</system.web>
</location>
</configuration>
也就是在需要認證的頁面配置節中不能配置authentication項,只能在在根目錄中配置authentication項,Info.aspx從根目錄繼承. 否則會出現這樣的錯誤: "在應用程序級別之外使用註冊爲 allowDefinition='MachineToApplication' 的節是錯誤的。如果在 IIS 中沒有將虛擬目錄配置爲應用程序,則可能導致此錯誤 "