asp.net-mvc IIS Express 自动为我的项目禁用匿名身份验证,为什么?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9743550/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
IIS Express is automatically disabling anonymous authentication for my project, why?
提问by Borek Bernard
When I switch my ASP.NET MVC project from Cassini web server to IIS Express, this is added to my applicationhost.configfile:
当我将我的 ASP.NET MVC 项目从 Cassini Web 服务器切换到 IIS Express 时,这将添加到我的applicationhost.config文件中:
<location path="MyProject">
<system.webServer>
<security>
<authentication>
<anonymousAuthentication enabled="false" />
<windowsAuthentication enabled="false" />
</authentication>
</security>
</system.webServer>
</location>
It's causing the site not to load with 401.2 - Unauthorized and I can't fix it on the Web.config level - it will then complain that the section is locked at parent level (HTTP 500.19).
它导致站点无法加载 401.2 - 未经授权,我无法在 Web.config 级别修复它 - 然后它会抱怨该部分被锁定在父级别(HTTP 500.19)。
I can fix it by amending the applicationhost.configfile but I don't understand why I should need to when no such section is added for a vanilla ASP.NET MVC project. What can be wrong?
我可以通过修改applicationhost.config文件来修复它,但我不明白为什么当没有为 vanilla ASP.NET MVC 项目添加这样的部分时我需要这样做。有什么问题?
I'm using VS 11 beta but also confirmed this weird behavior in 2010 SP1. IIS Express says it's version 7.5.
我正在使用 VS 11 测试版,但也在 2010 SP1 中确认了这种奇怪的行为。IIS Express 说它是 7.5 版。
回答by Borek Bernard
It was because for some reason, this was in my csproj file:
这是因为出于某种原因,这是在我的 csproj 文件中:
<IISExpressAnonymousAuthentication>disabled</IISExpressAnonymousAuthentication>
Setting it to enabledfixes the issue (it can also be done from Visual Studio, select project, F4, set Anonymous Authenticationin the properties grid to Enabled).
将其设置为enabled修复问题(也可以从 Visual Studio 中完成,选择项目,F4,将属性网格中的匿名身份验证设置为Enabled)。
回答by Raju S Nair
please right click on the project and select use iis express before pressing F4.
请在项目上右键单击并选择使用 iis express,然后按 F4。
回答by user3615318
Sometimes ago, I faced the same difficulty, but it was little different from what I see over here. In my laptop I have both VS 08 and VS 13, and SQL Server 2008 R2 and 11G XE. For websites connecting to R2 has never been a problem, but when I was trying to build a website using oracle membership with asp.net, I found that pages open but pages under folder with roles are not opening and giving me the access denied error. Though the folder had a proper web.config inside and the user created with the same role, still it was throwing up the same error. Finally I realized I need the authentication mechanism going and so I added the following code in the system.web of web.config:
有时,我也遇到过同样的困难,但这与我在这里看到的几乎没有什么不同。在我的笔记本电脑中,我有 VS 08 和 VS 13,以及 SQL Server 2008 R2 和 11G XE。对于连接到 R2 的网站从来都不是问题,但是当我尝试使用 oracle 成员身份和 asp.net 构建网站时,我发现页面打开但带有角色的文件夹下的页面没有打开并给我访问被拒绝的错误。尽管该文件夹中有一个正确的 web.config 并且用户使用相同的角色创建,但它仍然抛出相同的错误。最后我意识到我需要身份验证机制,所以我在 web.config 的 system.web 中添加了以下代码:
<authentication mode="Forms">
<forms loginUrl="Login.aspx" protection="All" slidingExpiration="true"
timeout="90" />
</authentication>
<authorization>
<deny users="?" />
</authorization>
<identity impersonate="false"/>
<trace
enabled="false"
requestLimit="10"
pageOutput="false"
traceMode="SortByTime"
localOnly="true"
/>
And it did work, now my authenticated users can loginto designated folders! I hope this might help someone who faced issues similar to me.
它确实有效,现在我的经过身份验证的用户可以登录到指定的文件夹!我希望这可以帮助遇到与我类似的问题的人。

