は、私が何を探しているがために、しかし、私はそれを行うことができます知っている... mixed mode authentication.
同様の質問を尋ねてきた 、like this.であると認められた答えはそれを行うことができないことだと思います私は混在モードの認証を持つプロジェクトも行った。私が何をしたか
されました:で
グローバルweb.config
(そうviews\web.config
の1ではない)に置く:
<authentication mode="Forms">
<forms loginUrl="~/Account/LogOn" timeout="2880" />
</authentication>
ので、デフォルトでは、それはあなたのアカウントコントローラに行います。
次にこれが私のコントローラです:
[HttpGet]
public ActionResult LogOn()
{
var loggedinUser = User.Identity.Name;
// If the logged in user is not empty, the session is not new.
// so the user wants to manually log in.
if (!string.IsNullOrEmpty(loggedinUser))
{
new SessionHelper(this).CleanupLeftoverCookies();
return View();
}
// Else try to get the windows login name.
loggedinUser = Request.ServerVariables["LOGON_USER"];
// I stored my active directory domain in the settings file, you can probably do this programmatically too
var domainName = Settings.Default.LDAPDomain;
loggedinUser = loggedinUser.Replace(string.Format(CultureInfo.InvariantCulture, "{0}\\", domainName), string.Empty);
// If there is no windows authentication either, let them login manually.
if (string.IsNullOrWhiteSpace(loggedinUser))
{
return View();
}
// Else store the windows Authentication in a cookie
if (ActiveDirectoryAuthentication(loggedinUser, false))
{
return RedirectToAction("Index", "Home");
}
else
{
ModelState.AddModelError(string.Empty, string.Format(CultureInfo.InvariantCulture, "Login using your windows account {0} failed. Please log in manually", loggedinUser));
return View();
}
// And go back home.
}
プロジェクトは、私の職場カントーにあるので、私は本当に私が覚えている以外の正確な詳細を与えることができません。私はあなたにコードサンプルを見せることができますが、月曜日よりも早くはありません。ただし、そのリンクを使用すると開始するのに役立ちます。 –
すごく楽しみです! – Jared
私のコードをまとめて質問を更新しました。 –