1

我们有一个 Visual Studio 向导,它可以生成具有不同设置的新 ASP.NET 项目,例如身份验证。

为 VS11 生成的应用程序安装“更新 2”后,当使用通过 HTTP 的基本身份验证时,得到 401.1 - 未经授权。如果我切换到开发服务器而不是 IIS Express,它就可以工作。

还有一件奇怪的事情。具有基本身份验证的项目可与 Visual Studio 2012 和 Visual Studio 2012 Update 1 中的 IIS Express 一起使用。IIS Express 的版本相同 - 8.0.8418.0。

这是我的调试尝试的结果:

1. credentials prompt rises
2. I'm typing login and password
3. method IsAuthorizationPresent() should be called but this does not happen!

使用 Development Server 时调用方法 IsAuthorizationPresent()。

public class BasicAuthenticationModule : AuthenticationModuleBase
{
    /// <summary>
    /// Checks whether authorization header is present.
    /// </summary>
    /// <param name="request">Instance of <see cref="HttpRequest"/>.</param>
    /// <returns>'true' if there's basic authentication header.</returns>
    protected override bool IsAuthorizationPresent(HttpRequest request)
    {
        string auth = request.Headers["Authorization"];
        return auth != null && auth.Substring(0, 5).ToLower() == "basic";
    }

... 

有谁知道为什么会这样?

Update1:​​重启后第二天就重现了。但它没有在另一台机器上复制,3天后也是如此。

更新2:它工作1-2次,然后几天不工作。

更新3:这是提琴手的回应:

HTTP/1.1 401 Unauthorized
Cache-Control: private
Content-Type: text/html; charset=utf-8
Server: Microsoft-IIS/8.0
X-AspNet-Version: 4.0.30319
WWW-Authenticate: Basic Realm="My Server"
X-SourceFiles: =?UTF-8?B?QzpcVXNlcnNcdGFyYXNcRG9jdW1lbnRzXElUIEhpdFxXZWJEQVY...
WWW-Authenticate: Basic realm="localhost"
X-Powered-By: ASP.NET
Date: Fri, 19 Jul 2013 09:22:45 GMT
Content-Length: 1961

您可以在此处看到两个“WWW-Authenticate”标头。在 web.config 中插入基本模块:

...
<add name="MyBasicAuthenticationModule" type="WebDAVServer.NtfsStorage.BasicAuthenticationModule, WebDAVServer.NtfsStorage" />
 </httpModules>
4

0 回答 0