簡體   English   中英

C#.NET MVC- HTTP 錯誤 403.14 - 禁止 Web 服務器配置為不列出此目錄的內容

[英]C#.NET MVC- HTTP Error 403.14 - Forbidden The Web server is configured to not list the contents of this directory

在 MVC 項目的根目錄下有一個 Startup.cs。

我啟用了目錄瀏覽。 但是在運行項目時顯示以下屏幕。 我希望在 MVC 項目中,不需要設置默認頁面。 我還嘗試在默認文檔(IIS)中添加 Startup.cs,但它會引發擴展被拒絕錯誤。 嘗試在 ApplicationHost.config 文件中添加.cs 擴展名。 但它給出了更復雜的錯誤。

Web.config

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.0" />
  </system.web>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true" />
        <defaultDocument enabled="true" />
        <directoryBrowse showFlags="Date, Time, Size, Extension, LongDate" />
  </system.webServer>  
</configuration>

HTTP 錯誤 403.14 - 禁止

目錄列表和 IIS 目錄瀏覽已啟用

將默認文檔設置為 Startup.cs 后出錯

這是在asp.net中啟用目錄瀏覽的完整配置

https://docs.microsoft.com/en-us/iis/configuration/system.webserver/directorybrowse

您無需瀏覽目錄即可顯示 ASP.NET MVC 站點。

但看起來你有一個非常舊的 web “服務器”。 您必須做的一件事是安裝 DotNetCore.2.0.0-WindowsHosting.exe(看起來您創建了 ASP.NET Core MVC 站點)。 查看本頁末尾: https://github.com/dotnet/core/blob/master/release-notes/download-archives/2.0.0-download.md

web.config 還必須包含所需的程序集。

編輯:

再次查看屏幕截圖后,您似乎已將項目中的所有源代碼添加到 web 服務器。 這不是它的工作方式。 您必須編譯 ASP.NET 項目並將其發布到 web 服務器(只需復制已編譯的輸出即可完成)。

我建議尋找 ASP.NET MVC 教程來掌握基礎知識。 並且可能嘗試使用更新版本的 IIS =D。

我剛剛發現這似乎顯示了基礎知識: https://www.tutlane.com/tutorial/aspnet-mvc/asp-net-mvc-publish-with-file-system

在用於提供文件的 IIS 中如果文件是腳本,則應添加處理程序,但如果應下載文件,則必須為其添加 MIME map。 注意要訪問任何文件,您應該啟用其擴展名(here.cs),然后在 URL 中引用帶有擴展名的確切文件名。 似乎您的 URL 不包含您的文件名。 還要注意您的文件不要位於 IIS 配置中的隱藏段中。

And if you are using asp.net core Some of the native IIS modules and all of the IIS managed modules aren't able to process requests for ASP.NET Core apps. 請參見此處( https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/iis/modules?view=aspnetcore-3.0 )。

此外,對於訪問被阻止的文件,您不需要啟用目錄瀏覽。 該文檔解釋了 iis 中的文件擴展: https://docs.microsoft.com/en-us/iis/configuration/system.webserver/security/requestfiltering/fileextensions/

您的案例將正確使用此配置:

 <system.webServer>
 <staticContent>
        <mimeMap fileExtension=".cs" mimeType="text/plain" />
 </staticContent>
 <security>
    <requestFiltering>
        <fileExtensions>
                <remove fileExtension=".cs" />
                <add fileExtension=".cs" allowed="true" />
          </fileExtensions>
     </requestFiltering>
 </security>
</system.webServer>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM