简体   繁体   English

Web服务器配置为不列出此目录的内容

[英]The Web server is configured to not list the contents of this directory

Using Visual Studio 2012: 使用Visual Studio 2012:

  1. I created an "ASP.NET Empty Web Application" (using C#). 我创建了一个“ASP.NET空Web应用程序”(使用C#)。
  2. I used NuGet to install the FubuMVC package. 我用NuGet安装了FubuMVC软件包。
  3. When I run the application (using IIS Express), I get the "Welcome to FubuMVC!" 当我运行应用程序(使用IIS Express)时,我得到“欢迎使用FubuMVC!” page which tells me to delete the FubuMVC.GettingStarted.dll file and to set the home page. 告诉我删除FubuMVC.GettingStarted.dll文件并设置主页的页面。
  4. So I do both of those things, implementing a HomeController that simply returns "Hello World" from Index . 所以我做了这两件事,实现了一个简单地从Index返回"Hello World"HomeController

Rather than the expected "Hello World", I get an IIS error: The Web server is configured to not list the contents of this directory. 我得到一个IIS错误:而不是预期的“Hello World”: The Web server is configured to not list the contents of this directory.

What have I done wrong? 我做错了什么?

try this cmd => don't forget to run as administrator 试试这个cmd =>别忘了以管理员身份运行

%windir%\\Microsoft.NET\\Framework64\\v4.0.30319\\aspnet_regiis.exe -ir %windir%\\ Microsoft.NET \\ Framework64 \\ v4.0.30319 \\ aspnet_regiis.exe -ir

Did you activate FubuMVC in your Global.asax? 你在Global.asax中激活了FubuMVC吗? I usually see that error when there is no FubuMVC application. 当没有FubuMVC应用程序时,我通常会看到错误。

So in Application_Start() (or whatever it's really called), you'll need something like: 所以在Application_Start()(或其他任何它真正被称为)中,你需要这样的东西:

FubuApplication.DefaultPolicies().StructureMap(new Container()).Bootstrap(); FubuApplication.DefaultPolicies()。StructureMap(new Container())。Bootstrap();

Where you're telling it: 1.) What are the policies/conventions to use 2.) What's your IoC container 你告诉它的地方:1。)使用什么政策/惯例2.)你的IoC容器是什么

Usually if I run into this it's because I've got a conflict with a route and a folder in the project. 通常,如果我碰到这个,那是因为我与项目中的路径和文件夹发生冲突。 For example, I might have a folder called 'Unit' and inside it I have a class called 'UnitEndpoint' with a method 'get_unit' (which should map to '/unit' as a route, assuming I'm using the FubuMVC defaults). 例如,我可能有一个名为'Unit'的文件夹,在其中我有一个名为'UnitEndpoint'的类,其方法为'get_unit'(应该映射到'/ unit'作为路径,假设我使用的是FubuMVC默认值)。

In that case, browsing to '/unit' will result in this error because IIS thinks I'm trying to list the contents of the 'Unit' folder. 在这种情况下,浏览到'/ unit'将导致此错误,因为IIS认为我正在尝试列出'Unit'文件夹的内容。 Renaming the endpoint or the folder to remove the conflict will fix it (eg, renaming the 'Unit' folder to 'Units'). 重命名端点或文件夹以删除冲突将修复它(例如,将“Unit”文件夹重命名为“Units”)。

Just tried reproducing your problem with a brand new project; 刚尝试用一个全新的项目来重现你的问题; it turns out that problem is that the instructions in the example haven't kept up with the changes in FubuMVC. 事实证明,问题在于示例中的指令未跟上FubuMVC中的更改。

The instructions tell you to create a class called 'MyHomeController' and add the Index() method to it. 说明告诉您创建一个名为“MyHomeController”的类并向其添加Index()方法。 This used to work, because one of the default rules for routes was to use any class with a name that ends in 'Controller'. 这曾经起作用,因为路由的默认规则之一是使用名称以“Controller”结尾的任何类。

But the default has been changed in more recent versions, and the rule now looks for classes ending in 'EndPoint'. 但是默认值已在更新版本中更改,并且规则现在查找以“EndPoint”结尾的类。

So if you change the name of the class from 'MyHomeController' to 'MyHomeEndpoint', it should work. 因此,如果您将类的名称从“MyHomeController”更改为“MyHomeEndpoint”,它应该可以正常工作。

Also, remember that the application pool needs to restart for the new configuration to take effect, so you might have to touch your web.config (or force IISExpress to restart). 此外,请记住,应用程序池需要重新启动才能使新配置生效,因此您可能必须触摸web.config(或强制IISExpress重新启动)。

我建议你重新编译你的应用程序或者至少触摸你的global.asax - 看起来你需要重新运行App_Start方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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