c# – 手动Windows身份验证
我目前正试图弄清楚如何在我们的ASP.NET应用程序中执行手动
Windows身份验证.问题是我们运行了OData服务,并使用FormsAuthentication提供通用登录机制并允许PUT&删除OData的动词,包括表单重定向.
但是,对于某些客户,我们集成了Windows身份验证,以便用户可以使用活动目录顺利集成.现在的问题是我们希望能够在不破坏Odata服务的情况下切换身份验证方法,因为我们依赖它. 我们要做的是使用IhttpModule模仿Windows身份验证机制.到目前为止,我们可以在&和关闭,我们在提出请求时接受挑战.我不知道的是如何使用从浏览器接收的信息对活动目录执行身份验证: 这是我们用于从当前请求中提取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. 解决方法
好的,
根据我的问题收到的评论,我提出了以下解决方案,以绕过我的问题.我知道这不是一个干净的解决方案,但至少它对我们有用. >创建在应用程序内运行的新Web应用程序 >禁用匿名身份验证&表单身份验证 >创建一个处理Windows身份验证的Login.aspx页面 这要求我们为加密生成相同的密钥.解密两个应用程序.可以使用IIS管理器中的机器密钥模块为您的应用程序设置此项.如果两个应用程序的密钥不相等,则cookie的编码/解码过程将失败.我们将它们设置为使用SHA1自动生成,但两个应用程序的密钥相同. 现在我们检查原始登录页面上的设置,如果需要Windows身份验证,则重定向到子应用程序的登录页面并在那里执行登录.然后我们重定向回原始登录页面并使用cookie继续. 这在初始登录时会导致一些重定向,但之后应用程序将像以往一样顺利运行. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |