【问题标题】:ASP.NET Mixed AuthenticationASP.NET 混合身份验证
【发布时间】:2015-09-15 20:21:27
【问题描述】:

我有 2 个应用程序,一个是表单身份验证,看起来像这样:

<authentication mode="Forms">
        <forms loginUrl="~/Login"></forms>
      </authentication>

public class LoginController : Controller
    {
        public ActionResult Index()
        {
            return View();
        }

        public ActionResult LoginCheck()
        {

            string username = Request.Form["username"];

            FormsAuthentication.RedirectFromLoginPage(username, true);

            return RedirectToAction("Index", "Home");
        }
    }

另一个应用程序是空的,但正在使用 Windows 身份验证:

<authentication mode="Windows" />

public class HomeController : Controller
    {
        public ActionResult Index()
        {
            ViewBag.Title = "Home Page";

            return View();
        }
    }

我想要做的是:

  1. 用户在表单认证申请中填写用户名和密码,点击提交

  2. LoginCheck 方法获取用户名和密码并针对 Windows 身份验证的应用程序进行身份验证

我希望我能从 Windows 身份验证应用程序中得到回复,说是,这个用户名和密码是正确的,继续,否则它们不起作用

我的目标是否正确?我的问题是我不知道如何完成第 2 部分,如果有人可以帮助我,那将是惊人的或指出我正确的方向。

【问题讨论】:

  • 为什么需要混音呢?如果 Web 堆栈在您的域中并且您可以访问 AD,为什么不使用 Windows 身份验证?如果不是,那为什么还要使用 windows auth?
  • 混合它是因为我想使用表单而不是丑陋的对话框。
  • 我很确定 Windows 身份验证发生在您的代码执行之前。您可能最好使用 Forms Authentication 和 ActiveDirectoryMembershipProvider,例如 this
  • 这是您的要求吗:- 应用程序应使用表单身份验证对 windows 用户进行身份验证,以便当前登录的用户不应仅使用其 windows 帐户绑定到登录应用程序。他应该可以使用任何有效的 Windows 帐户登录。

标签: c# asp.net authentication forms-authentication windows-authentication


【解决方案1】:

如果您出于其他原因不必使用第二个应用程序,我建议您使用其他方式来验证凭据。

示例: https://stackoverflow.com/a/499716/5036838

验证凭据后,您可以使用任何类型的 cookie/基于身份验证来继续。

【讨论】:

    【解决方案2】:

    使用集成 Windows 身份验证 (IWA) 时,您的浏览器应使用您的 Windows 凭据自动登录网站。

    您可以检查以下几点:

    • 您的浏览器是否支持 IWA?
    • 您的浏览器和网站之间是否有 HTTP 代理?
    • 您的计算机是否已登录到托管您网站的 Windows 域?
    • IE 设置是否指定提示输入凭据?

    有关更多建议,另请参阅this question 的答案。

    【讨论】:

      猜你喜欢
      • 2020-04-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-26
      • 2015-07-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多