ASP.NET MVC 5:应用程序池,Windows 身份验证和 Active Directory

ASP.NET MVC 5: App Pool, Windows Authentication and Active Directory

背景:

我有一个与外部接口的 MVC 5/C# 应用程序 API。它使用 Active Directory 用户的 Principal Context 进行授权。该应用程序检查 UserPrincipal.Current 是否将其 Un/Pw 组合存储在 Db 中,以便稍后在外部 API.

上进行任何操作
 public bool IsUserSetup()
    {
        try
        {
            // find currently logged in user
            var user = UserPrincipal.Current; // <- ERRS HERE -----
            // check if this user exists in Db with creds
            if (user != null)
            {
                var u = _userProfileRepository.GetUserProfileByUserSID(user.Sid.ToString());
                if (u != null
                    && !string.IsNullOrEmpty(u.RallyUsername)
                    && !string.IsNullOrEmpty(u.RallyPassword)
                    && u.IsActive // <-- make sure this person is an active user
                    )
                {
                    return true;
                }
            }
        }
        catch (Exception ex)
        {
            string exMessage = ex.Message;
            //throw ex;
        }
        return false;
    }

但是,如果我打开模拟 (true),则会得到:

An ASP.NET setting has been detected that does not apply in Integrated managed pipeline mode.

因此,我将 app pool 更改为使用 'classic'(我认为这不是我应该采用的答案或路径),但我收到此错误:

The page you are requesting cannot be served because of the ISAPI and CGI Restriction list settings on the Web server.

显然,这在 IIS Express 中运行良好,它认为我 (domain\username) 很好。但是当我将其切换到 IIS 或将其部署到实际的 Web 服务器时,我遇到了这些问题。

我需要获取当前 user/principal 以便我可以将它们的 SID 和凭据存储到 Db 中的外部 API。然后在使用 site/app 后,它会根据需要自动神奇地使用他们的信誉在 API 中工作。

我需要做什么:

来自 here,使用选项 2,即:

<system.webServer>
   <!--When using 'Integrated Pipeline' on IIS on the server, and if your application does not rely on impersonating the requesting user in the 'BeginRequest' and 'AuthenticateRequest' stages (the only stages where impersonation is not possible in Integrated mode), but still requires Impersonation in other areas of the application, ignore this error (500 - Internal Server Error) by adding the following to your application’s web.config-->
   <validation validateIntegratedModeConfiguration="false"/>
</system.webServer>