Asp.net

web.config allowDefinition=MachineToApplication 錯誤

  • March 21, 2022

在根目錄下,我有以下結構

..
..
..
web.config
Report Folder
- Login.aspx
- Web.config
 |
 |-> ViewReport
      |       
      |-> Report.aspx

在 Report 文件夾中的 web.config 文件中,我有以下內容:

   <?xml version="1.0"?>
   <configuration>
       <system.web>
           <authentication mode="Forms">
               <forms loginUrl="Login.aspx" defaultUrl="ViewReport/Report.aspx">
                   <credentials passwordFormat="Clear">
                       <user name="Johl" password="pass888"/>
                   </credentials>
               </forms>
            </authentication>
        </system.web>

       <location path="ViewReport/Report.aspx">
           <system.web>
               <authorization>
                   <allow users="Johl"/>
                   <deny users="*"/>
               </authorization>
           </system.web>
        </location>
    </configuration>

當我開始調試時,我收到以下消息:

在應用程序級別之外使用註冊為 allowDefinition=‘MachineToApplication’ 的部分是錯誤的。此錯誤可能是由未在 IIS 中配置為應用程序的虛擬目錄引起的。

請注意,在我的根 web.config 中,我有以下內容:

在我的根目錄中,我已經擁有以下內容:

        <system.web>        
           <authentication mode="Forms">
               <forms loginUrl="Str/StrUserLogin.aspx" timeout="2880" slidingExpiration="true"  />         
              </authentication>
           <authorization>
               <allow users="*" />
           </authorization>     
        </system.web>

在站點根目錄創建一個虛擬目錄。這可以通過 VS 中 Web 選項卡下的項目屬性來完成。

您也可能在子目錄中定義了應該在根配置文件中的東西。在這裡查看類似的問題:

使用註冊為 allowDefinition=‘MachineToApplication’ 的部分超出應用程序級別時出錯

將您的文件夾/項目轉換為 IIS 中的應用程序可以解決此錯誤。

引用自:https://stackoverflow.com/questions/16307112