[英]HTTP Error 401.2 - Unauthorized (for DefaultDocument)
我在VS2013(和IIS)中的默认文档上收到401.2错误。 这是我正在采取的步骤:
<?xml version="1.0" encoding="utf-8"?> <configuration> <appSettings> <add key="ValidationSettings:UnobtrusiveValidationMode" value="None" /> </appSettings> <system.web> <compilation debug="true" targetFramework="4.5" /> <httpRuntime targetFramework="4.5" /> <authentication mode="Forms"> <forms loginUrl="Login.aspx" /> </authentication> </system.web> <system.webServer> <defaultDocument> <files> <clear /> <add value="default.aspx" /> </files> </defaultDocument> <security> <authorization> <remove users="*"/> <add accessType="Deny" users="?" /> <add accessType="Allow" users="*"/> </authorization> </security> </system.webServer> </configuration>
我看到的行为是http:// localhost:12345 / Default.aspx行为正确(始终)。 换句话说,当我第一次进入Default.aspx时,它会将我重定向到Login.aspx页。 身份验证后,可以看到Default.aspx页面。 如果我注销并尝试再次转到Default.aspx页面,它将重定向到我首先登录。
但是,当我获得/ URL时(没有Default.aspx),我收到401.2错误(即使我已经通过1st身份验证)?
Default.aspx页被列为默认文档,并且如果我从Web.Config中删除“ Deny”行,则默认文档的行为将符合预期。 但是什么时候拒绝? 在Web配置中列出,默认文档突然停止工作,为了避免401.2错误,我必须转到/Default.aspx。
有什么暗示为什么会这样?
我在事件日志中没有发现任何有关此的错误。 使用IISExpress(在VS中按F5键)或直接通过浏览器访问公共URL时,使用IIS时,我会看到相同的行为。
我不愿提供此答案,因为我不完全了解为什么它对我有用。 但是,发表评论太久了,可能会对您有所帮助。
我发现将以下内容添加到System.Webserver
部分可以解决此问题:
<modules>
<remove name="FormsAuthentication"/>
<add name="FormsAuthentication" type="System.Web.Security.FormsAuthenticationModule" />
</modules>
关键似乎是从FormsAuthentication模块中删除managedHandler
前提条件。 据我了解,这仅应优化静态内容的投放。 因此,我现在不知道为什么会有这种效果。 我在尝试确定是否需要在System.Webserver
部分中注册FormsAuthentication模块时偶然发现了这一点。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.