我目前正试图弄清楚如何在ASP.NET应用程序中执行手动Windows身份验证。问题是我们有一个OData服务正在运行,并使用FormsAuthentication提供通用登录机制,并允许OData使用DELETE动词,包括表单重定向。手动Windows身份验证
但是,对于某些客户,我们已经集成了Windows身份验证功能,以允许其用户与活动目录顺利集成。现在的问题是,我们希望能够在不破坏Odata服务的情况下切换身份验证方法,因为我们依赖它。
我们试图做的是模仿使用IhttpModule的Windows身份验证机制。到目前为止,我们可以将&上的功能关闭,并且在发出请求时我们会面临挑战。我不知道如何使用收到的信息从浏览器对Active Directory执行验证:
这是我们用来提取当前请求的NTLM信息代码:
/// <summary>
/// <para>Determines whether the current <see cref="HttpRequest"/> is a NTML challenge.</para>
/// </summary>
/// <param name="request">The <see cref="HttpRequest"/> to evaluate.</param>
/// <param name="header">The output header to authenticate.</param>
/// <returns>True if the current <see cref="HttpRequest"/> is considered a NTML challenge.</returns>
protected bool IsNtlmChallenge(HttpRequest request, out string header)
{
const string headerName = @"Authorization";
if (request.Headers.AllKeys.Contains(headerName))
{
header = request.Headers[headerName];
return true;
}
header = string.Empty;
return false;
}
这使我们能够从请求中提取标题。我现在需要知道的是我如何在活动目录上执行身份验证。
这是我们用来提取信息的逻辑:
// Check if we need to handle authentication through Windows authentication or not.
if (WindowsAuthentication)
{
string encryptedHeader;
// If this is a challenge from the client, perform the Windows Authentication using the
// information stored inside the header.
if(IsNtlmChallenge(HttpContext.Current.Request, out encryptedHeader))
{
/* how to authenticate here with the encrypted header? */
}
HttpContext.Current.Response.AddHeader("WWW-Authenticate", "NTLM");
HttpContext.Current.Response.StatusCode = 401;
return;
}
希望有人能提供我需要的anwser。
伟大的问题 - 等待一个伟大的答案! –
我怀疑它可以混合窗体和Windows身份验证的方式。对于winauth,您必须在IIS中启用它(因为IIS将验证这些凭据),而win-auth和forms-auth不能在某些IIS设置(例如IIS7 +集成应用程序池)中一起使用。另外,您只能在web.config中指定一个auth模式。虽然使用经典的应用程序池,但您可能会混用身份验证,但不能使用相同的文件/文件夹。如果这是您正在运行的内容,请在特定文件夹/文件/ url路径(例如,aspx处理程序)上启用win-auth,然后使用该处理程序对win/AD用户进行身份验证。 – 2012-01-25 23:43:18
试试这个职位: http://stackoverflow.com/questions/2539038/iis7-mixed-mode-authentication – Tjaart