简体   繁体   中英

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

Theres a Startup.cs in the root directory of MVC project.

I enabled directory browsing. But On running the project shows the following screen. I hope in MVC project, there is no need to set default page. I also tried adding Startup.cs in Default document(IIS), But it throws extension denied error. Tried adding.cs extension in ApplicationHost.config file. But it gives more complex errors.

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 Error 403.14 - Forbidden

Directory Listing and IIS Directory browsing enabled

Error after setting default document to Startup.cs

Here is the complete configuration for enabling the directory browsing in asp.net

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

You do not need directory browsing on to display ASP.NET MVC site.

But it looks like you have a very old web "server". One thing you have to do is install DotNetCore.2.0.0-WindowsHosting.exe (it looks like you made a ASP.NET Core MVC site). Look at the end of this page: https://github.com/dotnet/core/blob/master/release-notes/download-archives/2.0.0-download.md

The web.config also have to include the needed assemblies.

Edit:

After a second look at your screen shots it looks like you added all the source code from your project to the web server. That is not how it works. You have to compile the ASP.NET project and publish it to the web server (can be done by only copying the compiled output).

I would recommend looking for a ASP.NET MVC tutorial to get a grip of the basics. And probably try with a newer version of IIS =D.

I just found this that seems to show the basics: https://www.tutlane.com/tutorial/aspnet-mvc/asp-net-mvc-publish-with-file-system

In IIS for serving files If the file is a script,you should add a handler but If the file should be downloaded, you must add a MIME map for it. Note for accessing to any file you should enable its extension (here.cs) then reference the exactly filename with extension in URL. Seem your URL is not contain your file name. Also be careful your file not be located in a hidden segment in IIS config.

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. see here ( https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/iis/modules?view=aspnetcore-3.0 ).

Also for accessing to blocked file you don't need enabling directory browsing. This doc explained fileExtensions in iis: https://docs.microsoft.com/en-us/iis/configuration/system.webserver/security/requestfiltering/fileextensions/

Your case properly will work with this config:

 <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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM