问题
This seems like a question that has already been asked/answered many times. Its not.
Development Environment: VS 2012 and MVC 4. I am using the built in IIS Express to run the app.
This error was not occurring until yesterday. It suddenly began to occur and I am stuck. Its strange that It occurs only in ONE scenario.
When I try to access http://localhost:49962/managescholars/, it shows me the error
HTTP Error 403.14 - Forbidden
The Web server is configured to not list the contents of this directory.
But using http://localhost:49962/managescholars/Index works fine. Other action methods of same controller also work fine. such as http://localhost:49962/managescholars/create. All other controllers work fine as well.
I have tried adding the following to web.config.
<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<modules runAllManagedModulesForAllRequests="true" />
<handlers/>
</system.webServer>
I also have tried running the following command as administrator
%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_regiis.exe -ir
But none of them worked.
Edit:
I have modified my routes. They look as follows.
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "ManageScholarLectures",
url: "Manage/Lectures/{userFriendlyName}",
defaults: new { controller = MVC.ManageLectures.Name ,
action = MVC.ManageLectures.ActionNames.Index,
userFriendlyName = UrlParameter.Optional }
);
routes.MapRoute(
name: "ManageScholarEdit",
url: "Manage/Scholars/{userFriendlyName}",
defaults: new { controller = MVC.ManageScholars.Name,
action = MVC.ManageScholars.ActionNames.Edit }
);
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = MVC.Home.Name,
action = MVC.Home.ActionNames.Index,
id = UrlParameter.Optional }
);
}
I am using T4MVC template.
It still does not work even if I leave the default route at the bottom and remove the first two routes. What have I done wrong?
Thanks a lot in advance for your help.
回答1:
Your routes seems fine. This should not cause any problem. The error is occuring only on http://localhost:49962/managescholars/ which means that there might be some other resource with same name.
Can you make sure your code does not mistakenly creates a folder managescholars during execution?"
回答2:
I encountered the same problem. To solve is very easy.
This problem occurs because of an IIS Express conflict when you edit the properties in the Protect URL in the Project settings. To solve this problem is very easy:
1 - Look for the file "applicationhost.config" in the ".vs \ config" directory. This folder is at the root of the solution. You can open it using Notepad ++
2 - Search for the name of your control using 'find' of your program (Ctrl + F). In my case, the control that gave problem was the 'Offices'.
3 - Delete any node where you place the IIS settings for such a URL. See example below:
<site name="G4.Admin(1)" id="8">
<application path="/" applicationPool="Clr4IntegratedAppPool">
<virtualDirectory path="/" physicalPath="C:\Projetos\PortalG4\src\G4.Admin" />
<virtualDirectory path="/Offices/Edit" physicalPath="C:\Projetos\PortalG4\src" />
<virtualDirectory path="/Offices" physicalPath="C:\Projetos\PortalG4" />
</application>
<application path="/Offices/Edit/2" applicationPool="Clr4IntegratedAppPool">
<virtualDirectory path="/" physicalPath="C:\Projetos\PortalG4\src\G4.Admin" />
</application>
<bindings>
<binding protocol="http" bindingInformation="*:6920:localhost" />
</bindings>
</site>
You should delete every element
<site name = "NAME_PROJECT" id = "X">
Note: Make a backup of the file before making the changes.
Hugs
回答3:
Firstly, I'm assuming that
http://localhost:49962/managescholars/
is in fact
http://localhost:49962/manage/scholars/
. If not there's your problem :)
I'm not an expert on routes, but in your route for Scholars the userFriendlyName param is not optional which means that http://localhost:49962/manage/scholars/ won't match any of your rules and IIS will treat it a request to list the content of the folder.
回答4:
Great !! In my case it was because I configured the application to run in a wrong url, but when I returned to the correct one, the look did not overwhelm the applicationhost.config.
As I said above, I only managed to solve those steps.
回答5:
In case someone get the same problem I got and enter this page deseperatly. If debugging website works but not on one website :
Check modification on global.asax Check if the route configuration is still present...
I know it's dumb but lost 6 hours after a git merge...
回答6:
I know original question is answered but below worked in my case. I got exact same issue on VS2013 using IIS Express. In my case visiting /Login was not getting Index action in LoginController. There was no physical folder when I checked but after more digging I found there was virtual directory created on IIS Express for /Login path which caused this. I deleted the virtual directory from applicationhost config(Documents\IISExpress\config) to resolve issue.
回答7:
In my case, with Visual Studio 2015, I solved the problem with the following steps:
- Stop IIS Express
- Close Visual studio
- Delete file applicationhost.config in {my solution directory}.vs\config
- Delete directory Documents\IISExpress\config
- Start VS, F5 and enjoy :)
回答8:
In my case, after using @Fl4v answer, I search for directoryBrowse attribute on file applicationhost.config in {my solution directory}.vs\config and there was false. Changed to true, restart iis and now it finnally works.
回答9:
You Should Go the username/ and enable it if not enable.
来源:https://stackoverflow.com/questions/17297490/http-error-403-14-forbidden-mvc-4-with-iis-express