我有一个场景,我要求用户能够使用Windows身份验证或Forms身份验证对ASP.NET MVC Web应用程序进行身份验证.如果用户在内部网络上,他们将使用Windows身份验证,如果他们在外部连接,他们将使用Forms身份验证.我见过很多人问这个问题我如何为此配置ASP.NET MVC Web应用程序,但我还没有找到完整的解释.
有人可以通过代码示例提供有关如何完成此操作的详细说明吗?
谢谢.
艾伦T.
以下帖子显示如何使用混合模式身份验证为站点设置web.config.IIS7混合模式身份验证以及如何在IIS 7.0中允许混合模式身份验证.
我有我的网站设置和本地工作(在我的开发人员机器上).但是,当我在服务器上本地运行它时,我得到401.2 - 由于服务器配置错误,登录失败.
任何人都知道我应该如何配置服务器,默认网站和我的网站?
编辑:以下是我的web.config中的设置,包括来自Forms身份验证节点的loginUrl.
<location path="~/Account/WinLogin.aspx">
<system.web>
<authorization>
<deny users="?"/>
<allow users="*"/>
</authorization>
</system.web>
<system.webServer>
<security>
<authentication>
<anonymousAuthentication enabled="false"/>
<windowsAuthentication enabled="true"/>
</authentication>
</security>
</system.webServer>
</location>
<system.web>
<authentication mode="Forms">
<forms loginUrl="~/Account/WinLogin.aspx" timeout="60"/>
</authentication>
<authorization>
<deny users="?"/>
</authorization>
Run Code Online (Sandbox Code Playgroud) 我目前正试图弄清楚如何在我们的ASP.NET应用程序中执行手动Windows身份验证.问题是我们运行了OData服务,并使用FormsAuthentication提供通用登录机制并允许OData的PUT和DELETE谓词,包括表单重定向.
但是,对于某些客户,我们集成了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;
}
Run Code Online (Sandbox Code Playgroud)
这允许我们从请求中提取标头.我现在需要知道的是我如何在活动目录上执行此身份验证.
这是我们用来提取信息的逻辑:
// Check if we need …Run Code Online (Sandbox Code Playgroud)